Subgraph Indexing & Querying Optimization: 4 Best Practices

Added:

Optimization Basics
Pruning with Hints
Pruning Considerations
Use Derived From
Derived Loaders
Bytes IDs & Immutable
ID Transition
Avoid Eth Calls
Declare Eth Calls
Future Practices

Optimization Basics

2:01
Playing Section
  • 1

    Subgraph performance hinges on database size and processing speed.

  • 2

    Small, optimized databases lead to faster query responses.

  • 3

    Focus on incremental efforts for significant gains.

Basic understanding of The Graph Protocol, including what subgraphs are and how they index blockchain data.
Proficiency in GraphQL query syntax and schema definition (GraphQL Schema Definition Language).
Understanding of EVM smart contracts and how state reads (specifically RPC 'eth_call' requests) interact with the blockchain.
Fundamental database concepts, such as indexing, query performance, and the trade-offs of different data types (e.g., string vs. byte representations).
Advanced subgraph design patterns, such as implementing indexing hand-off, handling chain reorganizations (reorgs), and multi-chain indexing.
Monitoring and debugging subgraph performance using indexer logs, Prometheus metrics, and query tracing.
Comparing decentralized indexing solutions with custom indexing pipelines built using SQL databases and custom Node/Rust daemons.
Integrating optimized subgraphs into production-grade decentralized applications (dApps) with robust caching and state management.
289 views31likes24:25@GraphProtocolOriginal Release: 2024-05-24

This video presents four key best practices for optimizing subgraph performance: (1) Pruning with indexer hints to automatically remove unused data and reduce database size; (2) Using @derivedFrom to manage arrays and prevent double-storage of entities; (3) Implementing bytes as IDs and immutable entities to achieve nearly 50% faster indexing and 25% faster query responsiveness; (4) Avoiding eth_calls or declaring them in the manifest to enable parallel execution and caching. These practices collectively reduce database bloat, accelerate indexing speed, and improve query responsiveness for production-ready subgraphs.