What happens during a consumer group rebalance, and how do you limit the damage?
Sketch your own answer first, then compare it with the one below.
A strong answer
When a member joins, leaves or fails, the group redeals partitions. In the simple protocol every member stops reading, then each partition resumes from its committed offset. During the pause producers keep writing, so lag builds. Work done since the last commit is read again.
Damage grows with frequent rebalances. Causes are slow processing that looks like a failure, flaky health checks, and rolling deploys that restart members one by one.
To limit it, tune timeouts so slow work is not mistaken for failure, restart members gently, commit more often, and use newer protocols that move fewer partitions at a time. Consumers must also be idempotent, because the repeat is built in.
Sources
- Jay Kreps, Neha Narkhede, Jun Rao (2011). Kafka: a distributed messaging system for log processing.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.