Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Design a Fault-Tolerant Stateful Stream
Processor with Barrier Checkpointing.

Inject Checkpoint Barriers at Kafka sources, snapshot local RocksDB state asynchronously via incremental SSTable delta uploads to S3, and switch to Unaligned Checkpoints if backpressure stalls alignment.
Start the journey5 stages· Last modified Nov 27, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When designing a stateful stream processor for <60s MTTR, pair incremental RocksDB S3 checkpoints with 5s Aligned-to-Unaligned barrier fallback.

TL;DR30-second simplified summary
▾

Incremental RocksDB hardlinks cut 30s uploads from 500 GB to ~1 GB, S3 refcounting protects shared SSTables, and Unaligned fallback prevents backpressure timeouts.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Chandy-Lamport Global Snapshots
Know how FIFO Markers capture consistent cuts and why Unaligned Checkpoints persist in-flight buffers.
RocksDB Incremental SSTables
Understand that immutable SSTables let incremental checkpoints upload only newly flushed files rather than all 500 GB every 30s.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

R & E · Requirements, State Volume & Incremental Upload Math.

500 GB of state across 200 tasks = 2.5 GB of RocksDB state per task.

Illustrative Sizing: A full 500 GB upload every 30s needs 500 GB / 30s = 16.7 GB/s (~133 Gbps) of S3 egress! With Incremental RocksDB Checkpoints, only MemTable flushes and compactions since Checkpoint N-1 create new SSTables. At 1M events/sec (~200 MB/s raw, ~20 MB/s dirty state churn after window aggregation), 30s of delta SSTables is only ~600 MB–1.5 GB cluster-wide (~3–8 MB per task)—uploading in <1 second!

Incremental Checkpoint Math

Full 500 GB Snapshot (16.7 GB/s) vs. Incremental SSTable Deltas (~1 GB/30s)

Before · Full Synchronous Backup
  • 500 GB uploaded every 30s
  • 16.7 GB/s S3 saturation
  • Processing stalls during upload
After · Async Incremental RocksDB
  • Hardlink local snapshot (<10 ms)
  • Upload ~1 GB new SSTables/30s
  • Zero pause on event path
02
L4 · FUNDAMENTALS

S · Storage: RocksDB Hardlinks & Shared S3 State Registry.

Because RocksDB SSTables are immutable, creating a local checkpoint (DB::CreateCheckpoint) simply creates OS hardlinks to active SSTable files in <5 ms—zero data copying!

Each task tracks shared_sstables already in S3. Checkpoint N only uploads new_sstables and writes a compact metadata manifest listing (sstable_id -> s3_uri) plus Kafka offsets. A Shared State Registry reference-counts every S3 SSTable across retained checkpoints.

Incremental S3 Registry

Checkpoint Manifest -> Shared SSTable Refcounts -> S3 Objects

03
L5 · APPLIED DESIGN

H & A · Barrier Injection, Alignment & Two-Phase Sink Commit.

The Checkpoint Coordinator periodically sends TriggerCheckpoint(N) to all Kafka Source tasks.

Each Source records its current Kafka partition offsets, snapshots nothing else, and injects Barrier(N) into all downstream partitions. Stateful operators align Barrier(N) across input channels, hardlink RocksDB, forward Barrier(N) downstream, and upload delta SSTables asynchronously.

Checkpoint Epoch N

Coordinator -> Source Barrier -> Operator Hardlink + Async S3 -> Sink Commit

CoordinatorKafka SourceRocksDB OperatorS3 + Sink1. TriggerCheckpoint(N)2. Record offsets + injectBarrier(N)3. Hardlink RocksDB + async deltaupload4. NotifyComplete(N) -> commitsink TX
04
L5 · APPLIED DESIGN

D · Detailed Design: Unaligned Checkpoints Under Backpressure.

In Aligned Checkpointing, if Input Channel 1 delivers Barrier(N) while Input Channel 2 is backed up behind 50,000 buffered events, the operator blocks Channel 1 waiting for Channel 2's barrier.

Under heavy backpressure, waiting for Barrier(N) to crawl through full TCP/Netty buffers can exceed the 30s checkpoint timeout! Enabling Unaligned Checkpoints with aligned_timeout = 5s lets the operator flip immediately if alignment stalls >5s: Barrier(N) overtakes the input/output buffers and the operator persists those in-flight buffers into S3 alongside RocksDB state.

Adaptive Barrier Mode

Aligned Barrier (<5s) -> Backpressure Stall -> Unaligned Spill -> Committed

all barriers < 5sstall > 5ssnapshot + buffers200/200 acksAligned WaitUnaligned Spill(5s+)Async S3 DeltaUploadEpoch N Committed
Engineering Decision Framework
Problem
How to keep 30s checkpoints completing on time across 500 GB of state even during downstream backpressure.
Naive Solution
Upload full 500 GB state synchronously or use strictly aligned barriers with no timeout.
Why It Fails
Full uploads saturate S3 at 16.7 GB/s; strictly aligned barriers time out whenever backpressure stalls one input channel.
Alternatives
Full synchronous snapshots vs. Aligned-only vs. Incremental RocksDB + Aligned-to-Unaligned Timeout.
Engineering Decision
Use Incremental RocksDB SSTable uploads (with Shared State refcounting) and Aligned Barriers with a 5s fallback to Unaligned Checkpoints.
Trade-Offs
Adds S3 reference-counting metadata management in exchange for <1 GB/30s uploads and backpressure-proof checkpoints.
Decision Exercise · Make the Call

During a downstream database slowdown, backpressure fills all Netty input buffers in your stream processor, and 30-second Aligned Checkpoints start timing out repeatedly. What fixes this without losing exactly-once guarantees?

05
L6 · SCALE & TRADE-OFFS

E & D · Evaluation, Assumptions, Limitations & Glossary.

Recovery speed (<60s MTTR) assumes S3 download parallelism across all 200 tasks and bounded Kafka replay lag (<=30s).

Assumptions & Limitations: Incremental delta size (~1 GB/30s) assumes typical window/keyed churn (~10% dirty state/min). If RocksDB triggers a massive full-level compaction across all 500 GB simultaneously, newly written compacted SSTables can cause a temporary spike in incremental upload volume—pacing compaction bandwidth avoids S3 bursts.

End-to-End Stream Engine

Kafka Sources -> Barrier Operators (RocksDB) -> S3 Registry -> 2PC Sink

Kafka Sources(Barriers)ingressRocksDB OperatorscomputeS3 Shared Registrystorage2PC Exactly-OnceSinkcontrol1M events/s + BarrierNasync delta SSTscommit on ack(N)
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does an incremental RocksDB checkpoint create OS hardlinks (`DB::CreateCheckpoint`) instead of copying 2.5 GB of state files per task?

Recommended Learning Flow