/On-Chain Event Indexing
📡

On-Chain Event Indexing

Day 1 · Smart Contract + Backend Integration · 30 min
ApproachProsCons
The GraphStructured, queryable, ecosystem supportDelay, hosted dependency, limited custom logic
Custom IndexerFull control, custom business logicDev overhead, maintenance burden
RPC PollingSimple to implementExpensive, unreliable at scale
Event SubscriptionReal-time, low latencyNode-dependent, connection drops
Production choice: Hybrid approach. Use The Graph for read-heavy queries, custom indexer for critical business events that need immediate processing.

Handling Reorgs in Indexers:

  • Store block number + block hash with every indexed event
  • On new block, verify parent hash matches previous block
  • If mismatch detected: roll back all events from orphaned blocks
  • Re-index from the fork point
  • Use a "finalized" flag — only set true after N confirmations
  • Key Points

    • Hybrid approach: The Graph for reads, custom indexer for critical events
    • Always store block number AND block hash with events
    • Verify parent hash chain to detect reorgs
    • Use finalized flag with confirmation threshold
    • Idempotent event processing is non-negotiable

    Navigate