Kafka · senior
Consumer groups and rebalances
Every time a consumer joins or leaves, the group rebalances. With the old eager protocol, all consumers stop while partitions are reassigned. Autoscaling can turn this into a loop.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Each partition goes to one consumer in the group, so parallelism is capped by the partition count.
- Every member joining or leaving triggers a rebalance. In an eager rebalance every consumer gives up all its partitions and waits for the new assignment.
- A loop on Kubernetes: a rebalance pauses work, CPU drops, the autoscaler removes pods, which triggers another rebalance, then the backlog raises CPU and pods are added again.
- Cooperative rebalancing (CooperativeStickyAssignor) moves only the partitions that change. The newer consumer group protocol (group.protocol=consumer, KIP-848) lets the broker compute assignments incrementally.
- Static membership (group.instance.id, stable per pod) lets a restart that returns within the session timeout keep its partitions without a rebalance.
- Scale on lag, not CPU, with a stabilisation window and the partition count as the maximum. Close the consumer cleanly on SIGTERM so it leaves the group at once.
- Other causes: max.poll.interval.ms exceeded because processing is slow, or health checks that kill pods.
- Do not raise session.timeout.ms to 10 minutes: a dead pod would then hold its partitions for 10 minutes.
The red pen
Common traps: mistake → fix
Mistake: Add more pods to go faster
Fix: more than the partition count sit idle and cause more rebalances.
Mistake: Rebalances are rare events
Fix: with autoscaling they can happen every few minutes.
Mistake: A very long session timeout is a fix
Fix: failures take much longer to detect.
Easy to hard
Questions interviewers ask, easy to hard
- Why does a consumer group rebalance every two minutes on Kubernetes?
- What is cooperative rebalancing?
- What is static membership?
- How should you autoscale Kafka consumers?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.