Unit 13 of 15 · about 6 hours · implement
A mini partition log with consumer groups and replay
This is the section's build: a log you can kill mid-append and a consumer group you can kill mid-commit, both recovering to matching offsets and outputs.
You'll be able to
- Implement a checksummed segmented partition log with offsets, an index, retention and recovery that truncates torn tails.
- Implement consumer-group ownership with epochs, committed offsets, kill-and-reassign replay and a retry and dead-letter boundary.
Covers
Read
In this order, only the parts listed
0 of 3 done
- The build ancestor to mirror and diverge fromKafka: a Distributed Messaging System for Log Processing (Kreps, Narkhede and Rao, 2011)
The log design to mirror (segments, offsets, pull consumers) and the final section to see what to add (replication and durability beyond fire-and-forget)
- The segment contract to compare againstApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols
Writes (serial append with segment roll), Reads (offset lookup with range checks), Deletes (time and size retention over whole segments)
- Milestones A to C requirementsReplicated Log and Stream Processor - Full Data Path
Milestone A (local checksummed log with recovery), Milestone B (instrumented histories), Milestone C (producer dedup, partition routing, consumer group with replay)
Focus on
- Appended, flushed, committed, applied and exposed are distinct states. Tests assert each transition separately.
- No wall-clock timestamp decides order; offsets do. Ownership moves with epochs so a stale consumer cannot commit past the new owner.
- Acknowledge only after the record is stable per the declared contract: flushed or replicated, never merely buffered.
- Compare each contract (retention, visibility, commit rule) with the Kafka 4.3 behavior and write down every deliberate difference.
Common mistakes · 3
- Acknowledging before the record is stable. An ack must follow flush or replication per the declared contract, never buffer acceptance.
- Letting two owners commit for one partition. Fence every commit with the ownership epoch.
- Testing only clean shutdown. Kill mid-append, mid-commit and mid-compaction; recovery must truncate the torn tail, never invent records.
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.A crash leaves a half-written record at the segment tail with a failing checksum. What does recovery do?Answer
It truncates at the last valid record and exposes nothing partial. The torn tail is discarded, never repaired by guessing.
2.Acks for offsets 0, 2 and 3 arrive but 1 is missing. What is the committed offset?Answer
Offset 0 is the end of the fully acknowledged prefix, so in Kafka's convention you store position 1, the next offset to read. The gap at 1 blocks 2 and 3 until it arrives.
3.A fenced-out consumer commits offset 8 after the group moved its partition to a new owner at epoch 7. Accepted?Answer
No. The commit carries the old epoch and is rejected. The new owner resumes from the last committed offset.
4.What evidence shows the build preserves its contract rather than passing clean-path tests?Answer
Deterministic kill schedules with retained raw histories: kill points at every append, commit and compaction boundary plus a minimized failing history for each bug found.
Practice
- AlgoMaster: Commit Contiguous Consumer Offsets
The committed offset is the greatest fully acknowledged prefix; out-of-order and repeated acks are safe; partitions stay independent
Drill the contiguous-commit rule here, on a subscription the learner owns. The section mini-project covers the full log with consumer groups, epochs and replay.
You're done when
The log survives kills at every boundary with matching offsets, the group reassigns without loss or silent duplication, and every Kafka deviation is written down.
Only when you can do this without notes.
Leads to
- An event-time processor with checkpointsProcess the log's events with checkpoints next.
- Lag, throughput, recovery and duplicate measurementMeasure the log you build here.
- Property-based state-machine testing with crash and restart, and deterministic schedule replayExplore its schedules with property tests later.
Notes
Resources · 3 for this unit, 15 more in the section
- 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.
- 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. - 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.
Also in this 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.