Consumer Group Rebalancing: Eager vs. Cooperative
Eager Rebalancing — The Naive Approach
The problem: A and B had to stop even though C's arrival didn't actually move their partitions. In a 100-consumer group, one new consumer joining pauses all 100 — 10–30 seconds of zero processing.
KIP-429: Cooperative/Incremental Rebalancing (Kafka 2.4+)
Instead of "revoke everything, then assign," figure out which partitions are actually moving, and only revoke those. Two rounds:
| Eager | Cooperative | |
|---|---|---|
| Who stops? | Everyone | Only consumers losing partitions |
| Rounds | 1 | 2 |
| Gap in processing | All partitions, all consumers | Only partitions actually moving |
Static Membership: group.instance.id
The problem: restarting one consumer causes two rebalances, even though the same worker comes straight back.
Why a restart normally costs two rebalances
By default, a consumer's identity in the group is a random member.id. It gets a new one every time it starts. So the coordinator can't tell "worker-3 restarted" apart from "worker-3 left and a stranger joined".
- Worker-3 shuts down. It sends
LeaveGroup(or, if it crashed, its heartbeats stop and it times out). → Rebalance #1: its partitions are handed to the other consumers. - Worker-3 starts again with a new
member.idand sendsJoinGroup. → Rebalance #2: partitions are moved again to include it.
A rolling restart of 10 consumers therefore causes about 20 rebalances.
The fix: give each consumer a fixed name
Set group.instance.id to something that stays the same across restarts, such as the pod name. Now the coordinator knows it's the same worker:
- Worker-3 shuts down. It does not send
LeaveGroup. The coordinator keeps its partitions reserved for it. No rebalance. - Worker-3 comes back within
session.timeout.msusing the samegroup.instance.id. The coordinator hands back the same partitions. No rebalance. - If it doesn't come back in time, the coordinator treats it as dead and runs one normal rebalance.
Without group.instance.id | With group.instance.id | |
|---|---|---|
| Identity | Random member.id, new on every start | Fixed name you choose (e.g. pod name) |
| On shutdown | Sends LeaveGroup → rebalance | Stays silent; partitions are held for it |
| On restart | Joins as a new member → rebalance | Gets its old partitions back |
| Rebalances per restart | 2 | 0 (if back within the timeout) |
The cost: while worker-3 is down, nobody reads its partitions. Their messages wait until it returns, or until the timeout expires.
Recommended config
partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor
group.instance.id=worker-pod-3
session.timeout.ms=45000The two settings cover different cases:
- Static membership removes rebalances for the common case: planned restarts and deploys.
- Cooperative sticky assignment keeps the remaining rebalances small (scaling up or down, real failures). Only the partitions that actually move are paused, not everyone's.