INTERMEDIATE⚙ Go Backend3-4hMilan
Swap Event Indexer
Build a Go service that listens for Uniswap V3 Swap events on Gnosis Chain, decodes them, and stores them in a PostgreSQL database. Exposes a REST API for querying swap history with filtering and pagination.
Tech Stack
Gogo-ethereum (ethclient)PostgreSQLsqlx or pgxchi router
What You'll Learn
- →Ethereum event log subscription and filtering
- →ABI decoding of indexed and non-indexed event parameters
- →Block reorganization handling
- →Database schema design for blockchain events
- →Pagination patterns for REST APIs
Milestones (0/4)
M2PostgreSQL storage layer
M3REST API with pagination
M4Reorg handling & graceful shutdown
Architecture Hints
Architecture
Key design decisions:
- Polling over WebSocket subscriptions (more reliable for production)
- Batch inserts with idempotent upserts (handle reorgs gracefully)
- Cursor-based pagination (more efficient than offset for large datasets)
- Checkpoint stored in DB alongside events (atomic consistency)
Gnosis Chain RPC
│
▼
┌─────────────┐ ┌──────────────┐
│ Poller │────▶│ Decoder │
│ (blocks) │ │ (ABI→struct)│
└─────────────┘ └──────┬───────┘
│
┌──────▼───────┐
│ Repository │
│ (batch ins) │
└──────┬───────┘
│
┌──────▼───────┐
│ PostgreSQL │
└──────┬───────┘
│
┌──────▼───────┐
│ REST API │
│ (chi) │
└──────────────┘Interview Talking Points
- ▸Discuss why polling is preferred over WebSocket subscriptions for production indexers
- ▸Explain reorg handling strategy and finality assumptions on Gnosis Chain
- ▸Talk about the indexer checkpoint pattern and crash recovery
- ▸Compare this approach to The Graph subgraphs — trade-offs of custom indexers