Unit 4 of 15 · about 4 hours · explain
Pull consumers, fetch positions, consumer groups and rebalance protocols
The consumer group is where ordering meets parallelism: each partition gets exactly one reader, and every membership change moves that reader. Rebalance behavior decides what pauses and what repeats.
You'll be able to
- Explain pull with fetch positions and why the broker keeps no per-message acknowledgement state.
- Explain consumer groups, partition ownership and static membership with
group.instance.id. - Explain rebalance generations and what pauses or duplicates a rebalance can cause.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Consumer groups and coarse-grained load balancingDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 12, Multiple consumers with Figure 12-1 (pp. 492 to 493): load balancing versus fan-out, consumer groups; Log-Based Message Brokers (p. 497): shard assignment to group members, single-threaded shard consumption, head-of-line blocking
- The consumer: pull, position and static membershipApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols
The Consumer (pull and long-poll rationale); Consumer Position (position as one integer offset with rewind support); Static Membership (
group.instance.idwith fenced restarts) - Consumer rebalance protocolApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols
Overview (KIP-848, generally available since 4.0: Consumer versus Classic groups, server-side assignors); Consumer (opt-in with
group.protocol=consumer); Upgrade and DowngradeRead the Overview and Consumer sections only. In 4.3 the Consumer protocol is opt-in; the 5.0 default change is out of scope.
Focus on
- Consumers pull and track one integer position per partition. The broker never tracks which message each consumer saw, which is why offsets are cheap.
- A group assigns each partition to exactly one member; two groups over one topic give fan-out across groups. Members beyond the partition count sit idle.
- Rebalance moves ownership on join, leave or crash, fenced by generations, with static members keeping partitions across rolling restarts. During the pause nobody reads the moved partitions.
- A member that processed records but did not commit before losing its partitions causes those records to be redelivered to the new owner.
Common mistakes · 3
- Adding more consumers than partitions to raise throughput. Extra members sit idle; raise partitions instead.
- Expecting KIP-848 behavior from default clients. In 4.3 the Consumer protocol needs
group.protocol=consumer. - Treating a rebalance as lossless by itself. Ownership moves; which records repeat depends on committed offsets, not on the protocol.
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.Six partitions, four live members, then a fifth member joins. How many members read, and with what split?Answer
All five read, split 2, 1, 1, 1 and 1, since each partition has exactly one owner. A member sits idle only when members outnumber partitions.
2.A member has committed position 10 (offsets up to 9 done), processes offsets 10 to 12, then crashes before its next commit, and its partitions move. Where does the new owner start, and what repeats?Answer
It resumes at 10, the committed position. Offsets 10 to 12 are delivered and processed a second time.
3.What does
group.instance.idchange on a rolling restart?AnswerThe restarted process rejoins as the same static member, so if it returns within the session timeout it keeps its partitions and no rebalance moves ownership. Records it processed but had not committed before the restart are still read again.
4.Why do log-based brokers pull instead of pushing?Answer
Pull lets each consumer control its rate, batching and replay position, and keeps the broker free of per-consumer acknowledgement state.
You're done when
You can assign partitions to any group size, predict the redelivery after a member death, and state when no rebalance happens at all.
Only when you can do this without notes.
Leads to
- Offset commits versus application state and at-most-once, at-least-once and effectively-once deliveryDecide what redelivery after a rebalance means for effects.
- Retries, poison records, dead letters and bounded backlogHandle the slow member that drags a partition next.
- A mini partition log with consumer groups and replayImplement ownership and replay in the mini log.
Notes
Resources · 2 for this unit, 16 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.
- 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.
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.
- 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.
- 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.