DocumentationGet Started

Get Started

Welcome to the documentation for building with Subgraphs and Substreams! This guide will help you set up your development environment and provide a foundational understanding to get started.

What are Subgraphs and Substreams?

Subgraphs

Subgraphs are modular and decentralized APIs designed to index and query blockchain data efficiently. Built using The Graph protocol, subgraphs serve as a key infrastructure layer for decentralized applications (DApps) by allowing developers to access on-chain data through GraphQL queries.

Use Cases

  • Decentralized Finance (DeFi):
    • Subgraphs are widely used by DeFi protocols like Uniswap, Aave, and SushiSwap to track critical on-chain events such as swaps, lending/borrowing activities, and liquidity pool changes.
    • They power analytics dashboards, performance tracking, and user-facing data visualizations.
  • Token Transfers and Interactions:
    • Enable tracking ERC20, ERC721 (NFTs), and other token standards, providing seamless insights into token transfers, balances, and contract interactions.
  • DApp Analytics:
    • Subgraphs allow projects to monitor adoption, engagement, and transaction metrics, enabling data-driven decision-making.
  • Simplifying Access to Blockchain Data:
    • Subgraphs abstract away the complexity of raw blockchain data, converting it into structured, queryable formats ideal for lightweight and real-time applications.

Advantages

  • Ease of Use: Subgraphs are simple to set up and provide high-level abstractions for querying blockchain data.
  • GraphQL Integration: Powerful and flexible query capabilities for dynamic frontend or backend applications.
  • Broad Adoption: Subgraphs are supported by an ever-growing ecosystem of decentralized protocols, making them a reliable standard for blockchain indexing.

Substreams

Substreams are high-performance data pipelines designed for streaming and transforming blockchain data. Built for scalability, substreams offer advanced processing capabilities for developers needing more granular control and real-time computations over large volumes of blockchain data.

Use Cases

  • High-Throughput Data Processing:
    • Ideal for handling high-volume blockchain networks or protocols with frequent updates, such as high-frequency DEXs or rollups.
  • Complex Aggregations:
    • Compute large-scale metrics like moving averages, cumulative totals, or historical trends (e.g., calculating token prices or TVL over time).
  • Low-Latency Applications:
    • Substreams reduce data retrieval latency, making them suitable for real-time dashboards and event-driven architectures.

Advantages

  • Efficiency: Substreams are optimized for large datasets, enabling fast processing without resource-heavy systems.
  • Composability: Substreams allow modular data pipelines, where multiple modules process data in parallel, improving performance and scalability.
  • Custom Transformations: Developers can define custom logic in Rust to process raw blockchain data, offering maximum flexibility.

Subgraphs vs. Substreams: Developer Perspective

Key Differences

AspectSubgraphsSubstreams
PurposeIndex and query blockchain data efficiently using GraphQL.Stream, process, and transform blockchain data at scale.
TechnologyBuilt on The Graph protocol, leveraging its decentralized indexing network.Developed for high-performance computation and scalable streaming pipelines.
Query LanguageUses GraphQL, offering an easy-to-learn query interface.Uses Rust and Protobufs for complex processing logic.
PerformanceSuited for moderate data loads and frequent queries.Optimized for high-throughput and low-latency processing.
Use Case FocusIdeal for user-facing analytics, dashboards, and lightweight querying.Best for backend services requiring aggregated, computed, or real-time metrics.
Ease of DevelopmentEasier setup with declarative mappings in TypeScript/AssemblyScript.Requires more development effort and expertise in Rust.
Example ProtocolsDeFi protocols like Uniswap, Compound, and Aave rely heavily on subgraphs for real-time analytics and dashboards.High-frequency data platforms, such as high-volume DEXs or rollup scaling solutions, use substreams for processing complex metrics and reducing query latencies.

When to Use Subgraphs

  • If you need to query historical or real-time blockchain data using a simple and structured approach.
  • When building analytics dashboards for DeFi protocols or NFT projects.
  • For applications requiring frequent queries but moderate computational complexity.

When to Use Substreams

  • If you’re working with high-volume blockchain data or require complex aggregations and transformations.
  • When building low-latency pipelines for real-time analytics or high-frequency trading platforms.
  • For backend services needing large-scale computations or streaming.