Video in progress
When does a rebalance start in a consumer group, and how does it affect the work?
A rebalance is the redistribution of the group's partitions among the consumers. It starts when a consumer joins, leaves, stops sending heartbeats, is too slow to poll, or when partitions are added to a topic. With the eager protocol the whole group stops reading during it.
📖 Answer
Typical events that trigger a rebalance:
- a new pod came up, or a pod restarted during a deploy;
- a pod died and no heartbeat arrived within
session.timeout.ms; - the listener spent longer than
max.poll.interval.mson one batch, so the consumer leaves the group on its own; - a new topic appeared, if you subscribed by pattern;
- the partition count changed.
In the old (eager) protocol every consumer gives up its partitions and then takes them again. For those few seconds nobody reads. In a rolling deploy, if 10 pods restart one after another, you get 20 rebalances and the lag spikes.
Lines to search for in the logs: Revoking previously assigned partitions, Successfully joined group, Member ... sending LeaveGroup request.
A rebalance isn't an error by itself, but if they happen often, that's a symptom. You can find the causes and reduce them with cooperative rebalancing or static membership.
Sign up to mark studied questions and save your progress.