What is a Kafka consumer group rebalance?
A consumer group rebalance is the process by which Kafka redistributes partition ownership among the members of a consumer group. It is triggered by membership changes (a consumer joining or leaving, a crash, or a heartbeat timeout), changes in the number of partitions for a subscribed topic, or a subscription change.
During a classic eager rebalance, all consumers revoke their current partition assignments, and then new assignments are computed and distributed. This stop-the-world pause halts consumption for all members — a significant problem for latency-sensitive workloads or large groups. To mitigate this, Kafka introduced cooperative incremental rebalancing (available since 2.4 via `CooperativeStickyAssignor`). In cooperative rebalancing, only the partitions that need to move are revoked and reassigned, allowing other partitions to continue being consumed during the process.
Rebalances are coordinated through the Group Coordinator broker. One consumer in the group is elected as the Group Leader and is responsible for computing the actual partition assignment using the configured `partition.assignment.strategy`. The result is sent back through the coordinator to all members.
From an application standpoint, the critical concern is offset handling during rebalance. A consumer must implement a `ConsumerRebalanceListener` to commit offsets for partitions being revoked (`onPartitionsRevoked`) before they transfer to another consumer. Failure to do this is the most common cause of message reprocessing after a rebalance, because the new owner will start from the last committed offset.
Common causes of excessive rebalancing include: heartbeat timeouts from long processing loops (`max.poll.interval.ms` exceeded), slow consumers removed due to missed polls, and aggressive session timeouts. Tuning `session.timeout.ms`, `heartbeat.interval.ms`, and `max.poll.interval.ms` — alongside switching to the `CooperativeStickyAssignor` — are the primary levers for reducing rebalance frequency and impact.
Knows what triggers a rebalance, that it causes a pause in consumption, and that offsets should be committed before partitions are revoked.
Distinguishes eager vs. cooperative incremental rebalancing, explains the role of the Group Leader in computing assignments, correctly identifies `max.poll.interval.ms` as a rebalance trigger, and mentions `ConsumerRebalanceListener` for safe offset handling.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment