Case study · Personal · Production
Reorg-safe Indexer
An Ethereum log indexer that treats the chain as unreliable: it rolls back reorgs, publishes only what passed its checks, and shows the evidence in a public dashboard.
- Real reorgs handled
- 41
- 7 days to 2026-10-24; all one block deep, 0 halts (docs/costs-and-load.md)
- Head lag p95
- 0 blocks
- Same window; p99 1 block, max 3 (docs/costs-and-load.md)
- Quality gate checks failed
- 0 of 357,623
- To 2026-10-24 (docs/costs-and-load.md)
- First backfill
- 50,000 blocks
- 0 rejects, 13.7 blocks/s, 2026-10-17 (docs/m1-gate.md)



The problem
Chain data pipelines usually fail quietly. A provider returns a short answer, a reorg replaces a block you already stored, or the process dies halfway through a write, and the table looks fine until somebody queries it. I wanted a pipeline where completeness is provable: every range is atomic, reorgs repair themselves, and a reader never sees data that has not passed its checks.
The scope is small on purpose, so the reliability work is the point: USDC Transfer events and the Uniswap v3 USDC/WETH 0.05% pool's Swap events on Ethereum mainnet, into Postgres, with a read-only API and a six-page dashboard on top.
Constraints
- Free, keyless public RPC providers with rate limits and 30-second timeouts. The first big run saw 12 timeouts and one rate-limit response, each retried on the next provider.
- One host and one Postgres node, with no replica and no standby indexer. A per-chain advisory lock allows exactly one writer.
- No paid RPC account. Live mode makes about 43,116 RPC calls a day (measured), several times the batch budget.
- Storage grows about 700 MiB a day before retention, so old data needs a policy.
- The API has no authentication, so it is read-only and binds to loopback by default.
Decisions
One transaction per block range, and the range row is the checkpoint
A crash leaves neither partial data nor a gap, and a separate checkpoint cannot disagree with the rows it describes. Resume is the last committed range plus one. Each range stores a payload hash, so re-committing is a no-op and different bytes for the same start block are an error. Rejected: per-block commits with a separate offset record.
Use the provider's finalized tag, and detect forks by parent hash
'N confirmations' is a guess that is wrong at some depth, and post-merge Ethereum has protocol finality. And eth_getLogs never tells you a stored log vanished, so each range's first header has to link to the stored hash below it.
Roll back whole ranges, and halt on a reorg below finalized
A range is either fully present with its checkpoint or absent, so the ledger and the per-range counts stay truthful. A finalized block reverting means a broken provider or a broken chain, which the indexer should not guess about: it exits with code 2 and stays halted until a person runs ack-halt with a written reason. Rejected: relying on the supervisor's exit code, which turned into a restart loop under Docker.
Fail closed: publish only after seven SQL gates pass
A range is published only when its last block is finalized and all seven gates pass. A failure marks the range failed and queues exactly one backfill job with a deterministic id (chain:from-to), so retries and crashes converge on one job. Rejected: publishing on commit and cleaning up later.
Re-read finalized ranges from a second provider and an Etherscan sample
Every internal gate trusts the provider that served the data, so a self-consistent provider that silently omits logs would pass all seven. Mismatches are recorded and need a human explanation. Etherscan is added because two RPC providers can share an upstream node.
Retain data by how it can be reacquired
About 700 MiB a day is mostly data that can be refetched or derived. Landing logs of published ranges are purged after 7 days and decoded rows after 14, and only once Parquet lists them. Blocks and the ops tables are never deleted. Rejected: one date-based TTL across every table.
What broke
A heap leak that only a 61-minute run could find
On 2026-10-17 the first 50,000-block backfill died with a Node out-of-memory abort (exit 134) after 230 of 500 ranges, with about 2 GB of heap in use. Every unit and integration test was green.
The cause: every await in the run loop raced one long-lived abort promise. Each Promise.race kept the already-settled fetch (about 9 MB per range) reachable, so a run longer than roughly 250 ranges could not finish.
Resume worked, so the gate was not blocked: the run restarted from the last committed range. The fix came after the gate (commit 09f5d43): the abort promise is created per call and its listener is removed when the awaited promise settles. A regression test that forces garbage collection keeps the old pattern failing.
Result
Backfill: 50,000 finalized mainnet blocks (500 ranges, 4,155,122 logs) with zero rejects. A kill -9 at range 60 of 500 resumed with no gap and no duplicate.
Live, over the seven days to 2026-10-24: 41 real reorgs (all one block deep) rolled back and converged with no halt, 49,158 ranges published, none failed, head lag p95 of 0 blocks, and no failure in 357,623 gate checks. The second-source checks matched everywhere: 49,234 ranges against dRPC and an 11,482-range Etherscan sample, nothing unexplained.
The decoded tables re-derive from the stored landing logs: a rebuild re-decoded 3,961,560 logs and the transfer and swap tables came out hash-equal. API latency on the deployed host is at or below 96 ms at p95 on every endpoint.
One miss since that readout, found by the second source and fixed. On 2026-10-28 block 26,288,697 was stored with 0 logs while dRPC saw 56. All seven gates had passed, because they only check what was stored; the reconciliation check is what caught it. On 2026-11-01 I confirmed that all five configured providers return 64 logs for the block, requeued it through the backfill job (the manual path in the runbook), and it republished with 56 logs. The other 34 blocks stored with zero logs were each confirmed empty by the second source. The cause, an empty answer for a fresh block at ingest time, is my hypothesis and was not reproduced. The cheapest defence I see is to re-read each block's logs from a second provider at finalization, before publishing; today that check runs after publication. It is not built. A logs-bloom check would not help: on busy mainnet blocks 63 to 80% of the header's bloom bits are set (measured on seven blocks), so it cannot tell a present address from an absent one.
Limits: one host and no standby. The 6.8 GiB retention steady state is computed, not yet observed, and the provider-budget figures are arithmetic from published prices, not measurements.
Stack
Figures checked against their sources on 2026-11-01. Each figure names the file or readout it came from.