Unit 10 of 15 · about 5 hours · explain, derive
Keyed state, checkpoint barriers and the source-state-sink recovery boundary
State makes streams useful and recovery hard: a restart must bring back the same derived state and the same input position together, or outputs silently double or vanish.
You'll be able to
- Explain keyed state partitioning and how rescaling reassigns key groups with their state.
- Derive the barrier snapshotting rule for acyclic graphs and the marker rules it inherits from Chandy and Lamport.
- Derive the source-state-sink recovery boundary: what restores, what rewinds, and which sinks keep exactly-once.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Asynchronous barrier snapshots for acyclic graphsLightweight Asynchronous Snapshots for Distributed Dataflows (Carbone et al., 2015)
The barrier broadcast and snapshot-on-receipt algorithm with its alignment discussion; the acyclic-graph scope. Barriers assume FIFO channels.
Study the acyclic case only. Skip the cyclic extension.
- Marker rules and consistent cutsDistributed Snapshots: Determining Global States of Distributed Systems (Chandy and Lamport, 1985)
The marker-sending and marker-receiving rules with the channel-state procedure, and why the recorded state is a consistent cut. Assumes FIFO channels with a spontaneously initiating process.
- Keyed state, barriers and recoveryApache Flink 2.3 - Event Time, State and Checkpointing
Keyed State; Checkpointing with Barriers (inline barriers, alignment, async write); Recovery (restore state and rewind sources such as Kafka offsets); Exactly Once versus At Least Once (when alignment skips trade down to duplicates)
- Rebuilding state after a failureDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 12, Fault Tolerance (pp. 526 to 528): Flink state snapshots, Kafka Streams changelog topics with log compaction, and rebuilding short-window state by input replay
Focus on
- Barriers flow with the data and separate pre-snapshot from post-snapshot records, so each operator snapshots a consistent cut without stopping the stream.
- Recovery restores operator state from the snapshot and rewinds replayable sources to the checkpointed offsets, then replays the suffix.
- Checkpoint exactly-once covers state and participating sinks only. Skipping alignment replays in-flight records, which non-idempotent sinks see twice.
- Keyed state partitions by key with the operator, so rescaling reassigns key groups together with their state instead of reshuffling records.
Common mistakes · 3
- Snapshotting without channel state or FIFO order. An in-flight record belongs to neither snapshot unless barriers order it.
- Restoring state but resuming sources from latest. Post-checkpoint inputs must replay or their effects are lost.
- Claiming exactly-once for a nonparticipating sink. A sink outside the checkpoint boundary repeats on recovery.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.An operator has one input channel. A record is sent on it right after a checkpoint barrier. Which side of the snapshot does the record fall on?Answer
The post-snapshot side. The snapshot holds state from pre-barrier records only; after a failure the source rewinds to the barrier position and the record is replayed.
2.A checkpoint restores operator state. What else must restore, and what happens if it does not?Answer
The source offsets must rewind to the checkpointed positions. Resuming from latest silently drops every post-checkpoint input.
3.What does skipping barrier alignment trade away, and when is it used?Answer
Flink's at-least-once mode skips alignment: it avoids stalling on slow channels under backpressure, but records from fast channels already reach the state before the snapshot and replay on recovery, so it trades exactly-once for progress. Unaligned checkpoints are the other route: the barrier overtakes in-flight records, which are stored in the checkpoint, so exactly-once holds at the cost of larger checkpoints.
4.A Kafka Streams task keeps a local aggregate. How does a replacement task rebuild it without a snapshot copy?Answer
It reads the dedicated changelog topic with log compaction, which holds the latest value per key, the same rebuild pattern as CDC from offset 0.
Practice
- AlgoMaster: Checkpoint Sidecar Log Delivery
The checkpoint advances only on acknowledged batches; a failed flush retries the exact batch; duplicate appends are rejected as reserved
A drill for the checkpoint-after-acknowledgement boundary, on a subscription the learner owns. Barrier alignment and state restore are mini-project work.
You're done when
You can run a barrier snapshot by hand on a small graph, state the full restore-plus-rewind procedure, and name which sinks keep exactly-once.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 14 more in the section
- DDIA 2e - Chapters 11 to 13 Batch and Stream ProcessingMartin Kleppmann and Chris Riccomini · primary
Read batch processing, stream processing and the streaming-systems philosophy in order. For every guarantee, mark the source position, operator state, output effect and recovery boundary it actually covers.
- Lightweight Asynchronous Snapshots for Distributed Dataflows (Carbone et al., 2015)arXiv · required
Read the asynchronous barrier snapshotting algorithm for acyclic graphs and its recovery; skip the cyclic extension. Barriers assume FIFO channels.
- Distributed Snapshots: Determining Global States of Distributed Systems (Chandy and Lamport, 1985)Leslie Lamport · support
Read the marker-sending and marker-receiving rules and why the recorded state is consistent. The algorithm needs FIFO channels.
- Apache Flink 2.3 - Event Time, State and CheckpointingApache Flink · required
Read the 2.3 concepts pages on time (event time, watermarks, lateness, windowing) and stateful stream processing (keyed state, checkpoint barriers, recovery, unaligned checkpoints, exactly-once versus at-least-once), then the watermark-generation guide on idle sources. Use them to build one bounded local processor; exactly-once covers state and participating sinks only.
Also in this section
- The Log: What Every Software Engineer Should Know About Real-time Data's Unifying Abstraction (Kreps, 2013)LinkedIn Engineering · support
Read it first as the short concept spine for logs, replicas, data integration and stream processing, before DDIA 2e Chapters 11 to 13.
- Kafka: a Distributed Messaging System for Log Processing (Kreps, Narkhede and Rao, 2011)NetDB workshop (mirror) · support
Read it as the design ancestor of your mini log: segments, offsets, pull consumers and consumer groups. Replication is future work in this paper, so take durability from the current docs.
- The Dataflow Model (Akidau et al., 2015)Google (author copy) · required
Read the model section: event time versus processing time, windowing, triggers and accumulation. Implement one trigger and one accumulation mode, not the catalog.
- MillWheel: Fault-Tolerant Stream Processing at Internet Scale (Akidau et al., 2013)PVLDB · support
Read low watermarks, persistent state, strong productions and exactly-once delivery by deduplication. The deduplication holds only within its retention bound.
- Apache Kafka 4.3 - Design, Log, Rebalance and Transaction ProtocolsApache Kafka · required
Read the 4.3 design page (replication and in-sync replicas, acknowledgements and
min.insync.replicas, delivery semantics, idempotence and transactions, the consumer, log compaction), the log implementation page, and the consumer rebalance protocol and transaction protocol pages (https://kafka.apache.org/43/operations/). Kafka 4.0 removed ZooKeeper. Run experiments in theapache/kafka:4.3.1image and compare each contract with your mini log. - Gossip Glomers - Kafka-Style LogFly.io and Jepsen · required
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 5a to 5c:
send,poll,commit_offsetsandlist_committed_offsetson one node, then two nodes overlin-kv, then with fewer messages. The checker catches lost writes and nonmonotonic or skipped offsets; it does not check recency or exactly-once effects. - AWS Builders' Library - Avoiding Insurmountable Queue BacklogsAmazon Web Services · support
Read it for how backlogs grow and why they take long to drain, and for backpressure, prioritization, sidelining and constant work. Compare its recovery strategies with the bounded backlog and lag measurements of your consumer.
- Confluent Schema Registry - Schema Evolution and CompatibilityConfluent · support
Use only the compatibility-type definitions (backward, forward, full and their transitive forms) as the vocabulary for your schema checks, with the Avro schema resolution rules as the mechanism.
- HLD Handbook - Queues, Streaming, Stream vs Batch and CDCHLD Handbook · required
Read only Part 2 message queues and pub-sub plus Part 4 stream versus batch and change data capture. Use Part 5 event-driven architecture after the underlying log and replay contract is clear.
- MIT 6.5840 - Lab 1 MapReduceMIT PDOS · support
Complete or review the coordinator and worker lab to connect deterministic batch dataflow, task retries and output publication. Do not confuse its shared-filesystem assumptions with the durable log contract.
- Replicated Log and Stream Processor - Full Data PathRoadmap-Final · support
Complete partitioned log, producer identity, consumer ownership, offsets, backpressure, event-time state, checkpoint, replay and sink boundary. Run the required producer, consumer, storage and late-data fault campaign.
- Apache Iceberg - Table SpecificationApache Iceberg · reference
Read the snapshot, manifest list and manifest sections for the read path, and the table metadata section for the atomic metadata-file swap that commits a snapshot.
- Delta Lake Protocol (pinned commit)Delta Lake · reference
Read the transaction log replay and checkpoint sections for how readers reconstruct table state, and the concurrency section for the optimistic commit rule.
- Apache Avro 1.12.0 Specification - Schema ResolutionApache Avro · reference
Read Schema Resolution only: records match by field name, writer-only fields are ignored, reader-only fields are filled from defaults, plus the promotion rules.