Lesson 5 of 9 · 27m
Consumer Groups, Rebalancing, and the Pause You Didn't Know You Had
Understand group membership, partition assignment, cooperative versus eager rebalancing, poll-loop deadlines, and the operational meaning of consumer lag.
Consumer groups are Kafka's load-balancing primitive, not merely a convenient way to run copies of a service. Every partition in a subscribed topic is assigned to exactly one active member of a group. When membership changes, Kafka reassigns partitions. If your processing is not designed around that reality, deployments look like duplicate-processing storms and slow handlers look like consumer death.
One group, one partition ownership
topic orders.events: 6 partitions
group invoice-projector
member worker-a partitions 0, 1
member worker-b partitions 2, 3
member worker-c partitions 4, 5If worker-c leaves the group, partitions 4 and 5 move elsewhere. During the move, processing pauses or duplicates may appear depending on assignment protocol and local commit behavior. Scaling the group beyond six members adds idle consumers, not more parallelism.
Separate groups are independent subscriptions
invoice-projector and fraud-scoring can both read the same topic without consuming each other's records. Groups share data, not positions. This is why Kafka supports multiple independent downstream systems naturally. It is also why resetting one group does not rewind the topic for anyone else.
Inspect active groups before assuming consumers are healthy:
kafka-consumer-groups.sh --bootstrap-server kafka-1:9092 --list
kafka-consumer-groups.sh --bootstrap-server kafka-1:9092 --group invoice-projector --describeLook for CURRENT-OFFSET, LOG-END-OFFSET, LAG, CONSUMER-ID, and HOST. Zero members with nonzero lag means nothing is processing, even if the topic is fine.
The poll loop is a heartbeat contract
Kafka clients prove liveness through the poll loop. Slow processing can make a member look dead:
max.poll.interval.ms=300000
max.poll.records=500If processing a batch takes longer than max.poll.interval.ms, the member is expelled and partitions rebalance. Teams often "fix" this by raising the interval to an hour. That hides the symptom and makes failure detection worse. Better fixes are smaller batches, asynchronous handoff with careful commit discipline, backpressure, or faster processing.
Eager versus cooperative rebalancing
Classic eager assignment stops the world: members revoke all partitions and receive a new assignment. Cooperative incremental assignment moves only the partitions that need to move:
partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignorCooperative rebalancing reduces processing disruption during rolling deployments, but it does not remove the need for idempotency. Shutdown, timeout, crash, or network partition can still create overlapping processing windows.
Lag is a symptom, not a diagnosis
A lag of two million means different things for different topics. Ask: how fast is traffic arriving, how expensive is processing, is lag growing, and did a rebalance or deploy just happen? A stable lag of thirty seconds may be healthy for batch enrichment. A small lag in a low-volume payments topic can be a serious incident if it represents stuck poison messages.
Poison records create partition stalls
One malformed or unprocessable record can halt a partition forever if the handler throws before committing. Production systems need a decision: retry with backoff, quarantine to a dead-letter topic, skip with audit, or repair upstream. Pretending the record will fix itself is not a strategy.
Field notes
- Static group membership (
group.instance.id) reduces rebalances during short restarts, but it does not replace correct fencing or idempotent handling. - Never share a group ID accidentally between unrelated applications; they will split partitions and half-process the workload.
- A consumer can be alive and unhealthy: poll succeeds while downstream writes fail or batch progress is zero.
- Rolling deploys should account for assignment movement. Drain or pause cleanly rather than killing mid-batch.
- Measure end-to-end latency, not only lag count. Offsets do not tell you how old events are.
Was this lesson helpful?