Data Engineering Reference/Deep Cuts (Platform)

Flink State, Checkpoints & Exactly-Once

Keyed state, checkpoint barriers, savepoints, state backends (RocksDB), and end-to-end exactly-once with Kafka + two-phase commit sinks.

5/5Overview: 30m

Flink state

Stateful operators keep keyed state across events:

  • Aggregations (counts, sums)
  • Session windows
  • Join buffers

State lives in state backends:

BackendStorage
HashMapJVM heap (dev, small state)
RocksDBLocal disk + async to checkpoint (production)

Checkpointing

Chandy-Lamport snapshot algorithm via checkpoint barriers:

  1. Job manager injects barrier into streams
  2. Operators snapshot state when barrier arrives
  3. All state + offsets persisted to durable storage (S3/HDFS)

On failure: restart from last completed checkpoint.

Savepoints vs checkpoints

CheckpointSavepoint
TriggerAutomatic periodicManual
UseFault recoveryUpgrades, migrations, A/B
RetentionConfigured countUntil deleted

Upgrade flow: stop job → savepoint → deploy new code → resume from savepoint.

Exactly-once

Flink + Kafka source (offset in checkpoint) + two-phase commit sink:

  1. Begin transaction
  2. Write output
  3. Commit on checkpoint complete

Sink must participate (Kafka, JDBC with XA, some Delta connectors).

Link to Topic 8 and Distributed Systems — end-to-end guarantees need idempotent sinks even with checkpoints.

Backpressure

Flink propagates pressure upstream — slow sink → slower source read. Tune parallelism and buffer-timeout.

Interview answer template

"RocksDB state backend, 5-minute checkpoints to S3. Kafka offsets in checkpoint for exactly-once read. Before deploy, trigger savepoint, cancel job, resume with allowNonRestoredState only if we dropped an operator. Monitor checkpoint duration — exceeding interval means backpressure."

Further Reading

Hands-On Tasks (Optional)

Pipeline design drills and whiteboard exercises — DAG sketches, partition plans, backfill strategies. Assumes Databases and SQL fundamentals are in place.

  • Upgrade a Flink job safely

    Deploy new logic for a stateful aggregation job. Describe savepoint vs checkpoint, state schema compatibility, and rollback plan.

    15m