Module A-6·24 min read

The real-world problem: 10+ multithreaded Node.js instances processing Kafka-delivered blockchain blocks at 2,000+ TPS without double-processing. Block-range partitioning via Redis locks, heartbeat extension, crash recovery, and the 6-hour replication lag incident.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

A-6 — The SupraScan Architecture: Coordinating 10+ Concurrent Scanner Instances

This module is different. The previous modules covered Redis primitives in theory and controlled examples. This module is a case study from production: building a distributed blockchain indexer that processes Kafka-delivered blocks at 2,000+ transactions per second across 10+ concurrent Node.js instances. Every technique from this course is here — distributed locks, Redis coordination, crash recovery, memory management under load, and the failure modes that only appear at production scale.


The Problem

SupraScan is a blockchain indexer for the Supra L1 network. Its job: consume every block from Kafka, parse every transaction, and write structured data to PostgreSQL — with no missed blocks, no duplicate processing, and no gaps in the indexed history.

The constraints:

  • Throughput: 2,000+ transactions per second at peak
  • Concurrency: 10+ worker instances, each multi-threaded (Node.js cluster + worker threads)
  • Ordering: Blocks must be indexed in strict sequence (block N before block N+1)
  • Durability: The indexed data is the only source of historical state — unavailable via on-chain RPC. No data loss is acceptable.
  • Availability: Processing must resume automatically after any worker crash
  • Historical data: The indexer's complete historical dataset became foundational infrastructure consumed by multiple cross-functional teams across analytics, product, and research — this elevated the cost of any data loss or gap

The fundamental challenge: distributed coordination without a central coordinator. Every worker is equal. Any worker can crash at any time. No worker has special authority.


The Architecture

text

Redis is the coordination layer — it holds lock state, progress tracking, and health signals. PostgreSQL is the data store. Kafka is the event source.


Block-Range Partitioning via Redis Locks

Each Kafka partition delivers blocks in order. Multiple workers consume from multiple partitions simultaneously. The challenge: if two workers consume the same block (e.g., due to consumer group rebalancing), they must not both write it to the database.

Solution: Block-range locks.

Before processing a block range (e.g., blocks 100,000–100,099), a worker acquires a Redis lock for that range:

SET lock:block:range:100000 {worker_uuid} NX PX 60000

If the lock is acquired, the worker owns that range exclusively. If another worker also tries to process the same range (due to consumer group rebalancing, duplicate delivery), it sees the lock and skips.

typescript

Idempotency Check

Before acquiring the lock, check if this range was already completed (by a previous run or another worker that finished and released the lock):

typescript

The complete:* keys have a 24-hour TTL — sufficient to prevent reprocessing during normal operation while not accumulating indefinitely.


Progress Tracking: Sorted Set as a Processing Frontier

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.