Rebalance — stop-the-world vs. cooperative
Eager rebalance revokes every partition from every consumer on any membership change, while cooperative rebalance (KIP-429) only revokes partitions that are actually moving — turning a 14-minute outage into a 1-minute brief gap on a couple of lanes.
Followers and leaders are sorted. Now the OTHER source of churn: consumers come and go, and the group has to reassign partitions. Eager rebalance is a 14-minute outage; cooperative is a 1-minute brief gap.
Scene 07
Rebalance — stop-the-world vs. cooperative
- Watch
- Try it
- Predict
- Capture
Four consumers split six partitions. Watch the lanes — they're all green (active). At tick 8, C0 exceeds max.poll.interval.ms; the group enters PreparingRebalance and every lane goes dark for a few ticks. Watch what happens to the lanes that AREN'T moving.
Highlighted lines are the ones running in the diagram right now.
def onJoinGroup(member):group.state = PreparingRebalance# signal EVERY member to drop EVERY partitionfor m in group.members:m.send(RevokeAll)await m.onPartitionsRevoked_done# group is idle here — nobody owns anythingplan = assignor.assign(group.members,group.subscribed_topics)group.generation += 1for m, parts in plan.items():m.send(SyncGroup(parts))group.state = Stable
def onPartitionsRevoked(partitions):# everything below runs while the lane is BLACKfor p in partitions:consumer.commitSync(offsets[p])stateStore[p].flush()stateStore[p].close()# Streams: local RocksDB rebuilt on the next assignmentmetrics.record('revoke.latency', now() - t0)# only after this returns does Coordinator proceed
Where this sits in Build Kafka
Scene 07 of 13, in the Scale act — Rebalancing without halting every consumer.. Eager revokes everyone; cooperative-sticky only the lanes that move.
Up next. Exactly-once — when retries, restarts, and rebalances all stack up, what stops a duplicate or a zombie writer? Three independent monotonic counters do it.
Designs that use this
- Twitter / X TimelinePush or pull? Both. The canonical fanout problem.
- Uber / Lyft — Match Drivers and RidersMatch a rider to the closest acceptable driver in under 3 s. Geohash, S2, surge.
- Slack / DiscordChannels and history. Push or pull — and how a hot-channel fanout doesn't melt the gateway.
- WhatsApp / MessengerHundreds of millions of long-lived sockets, sub-second 1:1 + group delivery, E2E-encrypted, multi-device, multi-region active-active.