Building Subgraphs on The Graph: A Developer Tutorial

Added:

Alternative Indexing Solutions and Subgraph Performance Bottlenecks

While The Graph is a pioneer in decentralized blockchain data indexing, developers frequently encounter performance and architecture bottlenecks when building subgraphs. Subgraphs rely on sequential processing and AssemblyScript, which can lead to slow sync times—sometimes taking days or weeks for data-heavy protocols on high-throughput chains. Consequently, a growing counter-perspective advocates for alternative indexing solutions like Subsquid, Goldsky, or custom self-hosted indexers. Frameworks like Subsquid decouple data ingestion from data transformation, using parallelized architectures and native TypeScript to significantly accelerate indexing speeds. Furthermore, critics point to the high complexity and query costs associated with The Graph's decentralized network compared to centralized or hybrid managed databases. For many developers, these alternatives offer superior sync performance, lower latency, and more flexible querying capabilities (such as full SQL support) at a fraction of the time and cost, challenging the necessity of using The Graph for every Web3 application.

Basic understanding of Ethereum, smart contracts, and how decentralized applications (dApps) execute transactions.
Familiarity with GraphQL query syntax, schemas, and basic data types.
Proficiency with development tools such as Node.js, npm/yarn, and interacting with Command Line Interfaces (CLI).
Fundamental concepts of data indexing and why standard blockchain RPC nodes are inefficient for complex querying.
Integrating queried subgraph data into frontend applications using client libraries like Apollo Client or Urql.
Writing robust unit and integration tests for subgraphs using the Matchstick testing framework.
Deploying subgraphs to the decentralized Graph Network and managing curation, indexer fees, and GRT staking.
Implementing advanced subgraph features such as multi-chain indexing, handling blockchain reorgs, and schema optimizations for high-throughput dApps.
12.3K views215likes59:19@ETHGlobalOriginal Release: 2020-10-06

A subgraph on The Graph is a data indexing and querying system built on top of Ethereum that allows developers to create GraphQL APIs for blockchain data by combining three core components: a manifest file (YAML) that defines data sources and event handlers, a GraphQL schema that defines how data should be stored and queried, and mapping functions (written in AssemblyScript) that process on-chain events and save data to the database; developers can deploy subgraphs to The Graph's hosted service using the Graph CLI, which handles the underlying infrastructure, and can leverage existing community-built subgraphs like Uniswap or create their own custom subgraphs for various use cases.