High-Level Architecture
Core Components
Graph Node is organized into specialized crates, each handling a specific aspect of the indexing pipeline:graph/: Core abstractions, traits, and shared typesnode/: Main executable and CLI (graphman)chain/: Blockchain-specific adapters (Ethereum, NEAR, Substreams)runtime/: WebAssembly runtime for subgraph executionstore/: PostgreSQL-based storage layergraphql/: GraphQL query execution engineserver/: HTTP/WebSocket APIs
Data Flow Pipeline
The indexing pipeline follows a clear, event-driven flow:Chain Adapters
Connect to blockchain nodes and convert data to standardized formats.Each blockchain has its own adapter in the
chain/ directory:chain/ethereum: Ethereum chain supportchain/near: NEAR protocol supportchain/substreams: Substreams data source support
Block Streams
Provide event-driven streaming of blockchain blocks.Block streams deliver blocks in order and handle reorgs automatically.
Trigger Processing
Matches blockchain events to subgraph handlers.The trigger processor filters events based on the subgraph manifest and determines which handlers to invoke.
Runtime Execution
Executes subgraph code in a WebAssembly sandbox.The runtime provides:
- Gas metering for resource control
- Host functions for accessing blockchain data
- Isolated execution environment
Store Persistence
Persists entities with block-level granularity.The store supports:
- Multi-shard database configuration
- Time-travel queries
- Efficient indexing and querying
Crate Structure
Core Crates
Blockchain Integration
Each blockchain has dedicated support through specialized adapters:chain/ethereum: Ethereum chain support with full RPC integrationchain/near: NEAR protocol supportchain/substreams: Substreams data source support for high-throughput indexing
Infrastructure Crates
Key Abstractions
Blockchain Trait
The core blockchain interface that all chain adapters must implement:Store Trait
Storage abstraction with read/write variants:RuntimeHost
WASM execution environment that provides:- Sandboxed execution of subgraph code
- Gas metering for resource control
- Host functions for accessing blockchain data
- Memory management and security
TriggerData
Standardized blockchain events that trigger subgraph handlers:- Event logs
- Function calls
- Block data
- Transaction receipts
EventConsumer/EventProducer
Component communication patterns:- Async message passing between components
- Backpressure handling
- Error propagation
Architecture Patterns
Event-Driven Architecture
Components communicate through async streams and channels, enabling:
- Loose coupling between components
- Natural backpressure handling
- Efficient resource utilization
Trait-Based Design
Extensive use of traits for abstraction and modularity:- Easy to add new blockchain support
- Testable through mock implementations
- Clear separation of concerns
Async/Await Throughout
Tokio-based async runtime used throughout the system:- Non-blocking I/O operations
- Efficient handling of concurrent requests
- Scalable to thousands of subgraphs
Multi-Shard Database
The store supports sharding to handle large-scale deployments:- Horizontal scaling of database load
- Independent backup and maintenance
- Optimized query routing
Sandboxed Execution
WASM runtime provides secure, isolated execution:- Gas metering prevents infinite loops
- Memory limits prevent resource exhaustion
- Host function allowlist controls access
Key Dependencies
Graph Node relies on several critical dependencies:Component Interaction Example
Here’s how components work together when indexing a subgraph:Development Guidelines
Commit Convention
Use the format:{crate-name}: {description}
Git Workflow
- Rebase on master (don’t merge master into feature branch)
- Keep commits logical and atomic
- Squash commits to clean up history before merging
Performance Considerations
Database Optimization
- Use appropriate indexes for query patterns
- Consider database sharding for large deployments
- Monitor query performance with
EXPLAIN ANALYZE
Memory Management
- WASM instances are pooled for reuse
- Entity caching reduces database load
- Careful memory limits prevent OOM conditions
Concurrency
- Multiple subgraphs index in parallel
- Database connections are pooled
- Async I/O prevents thread blocking

