Consumer group rebalance pauses during a zero-downtime Kafka application migration
0 reputation · 16 Dec 2020, 04:18 UTC
0 reputation · 16 Dec 2020, 04:18 UTC
A small Kafka consumer application is being moved to a new deployment, and the goal is to keep message processing continuous while old and new instances briefly share the consumer group. Each membership change in that window triggers a rebalance, and the assignment protocol decides how much of the group stops consuming.
Under an eager assignor such as RangeAssignor, any join or leave revokes every partition from every member until reassignment completes. The cooperative-sticky assignor, available in Java clients since Kafka 2.4, revokes only the partitions that actually move, which narrows the gap but pushes more work onto the application: revoke and assign callbacks must tolerate incremental changes, and duplicate processing remains possible.
The unresolved part is offset commit timing around revocation. Committing before processing finishes can lose records if a partition is handed off mid-batch, while committing afterward invites duplicates during the rebalance window. A slow rebalance can also push a member past max.poll.interval.ms, prompting eviction and further rebalances, and mixed client versions or differing partition.assignment.strategy settings within one group can change rebalance behavior.
Which assignment strategy fits a short rolling migration of a small consumer group? How should offset commits be timed relative to partition revocation so the transition causes neither message loss nor unbounded duplicates?
34275 reputation · 16 Dec 2020, 13:38 UTC
For a short rolling migration of a small consumer group, the org.apache.kafka.clients.consumer.CooperativeStickyAssignor is the appropriate assignment strategy. Offsets should be committed synchronously inside the ConsumerRebalanceListener.onPartitionsRevoked callback before the partition is released.
partition.assignment.strategy setting; otherwise the group falls back to the least common denominator strategy.partition.assignment.strategy=org.apache.kafka.clients.consumer.CooperativeStickyAssignor on every instance (old and new).ConsumerRebalanceListener:onPartitionsRevoked, synchronously commit offsets for the partitions being revoked (use commitSync or transactional commit if applicable).onPartitionsAssigned, resume processing; no special commit is needed here.max.poll.interval.ms is larger than the expected worst‑case rebalance time (including the synchronous commit). If it is not, increase it to avoid premature eviction.max.poll.records) to limit the amount of data that could be duplicated if a crash occurs between processing and committing.join-group and sync-group requests; they should show that not all members lose all partitions simultaneously.org.apache.kafka.clients.consumer) to see which partitions are listed in onPartitionsRevoked and confirm they match the expected moving set.max.poll.interval.ms expires.If you are unsure whether the current max.poll.interval.ms setting accommodates the rebalance plus commit time, please provide that value so we can confirm it is sufficient or advise an increase.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.