Kafka StickyAssignor breaking delivery to single consumer in the group
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a distributed event streaming platform capable of handling trillions of events a day. One of Kafka's strengths lies in its flexible consumer group feature, where a set of consumers share a common group ID to jointly process records published in the topics they subscribe to. In Kafka, the assignment of topic partitions to consumers within a group is managed by partition assignment strategies, among which the StickyAssignor is a popular choice due to its attempt to minimize partition movement across consumers.
Understanding StickyAssignor
The StickyAssignor algorithm aims to maintain a stable partition assignment even as consumers join or leave the group. It tries to ensure that partition assignments stick with the original consumer as much as possible. This stickiness is beneficial because it reduces the need for extensive rebalancing and minimizes the potential for duplicate message processing during consumer changes.
Issue: Breaking Delivery to Single Consumer in the Group
Occasionally, usage of the StickyAssignor can lead to scenarios where one consumer in a group might end up not receiving any partitions, especially in groups with a small number of partitions relative to the number of consumers. This can occur due to the inherent design of how the StickyAssignor tries to distribute partitions as evenly as possible while trying to maintain previous assignments.
Technical Explanation
Consider a scenario with 3 partitions (P0, P1, P2) and 3 consumers (C0, C1, C2) in a consumer group. If all consumers have been active and are reassigned together, the sticky nature will attempt to allocate the same partitions to the same consumer:
C0getsP0C1getsP1C2getsP2
If C1 is then stopped and a reassignment occurs, C0 and C2 might still attempt to stick with P0 and P2, respectively. When C1 rejoins, another reassignment is triggered. Ideally, C1 should get back P1, but based on the state of the current consumers and partitions, C1 might end up without any partitions if the algorithm determines that sticking with previous assignments (C0 with P0 and C2 with P2) as exactly before provides a more minimal change.
Example with Code
Here is a hypothetical snippet illustrating a potential breakpoint where rebalancing might result in a consumer getting no assignments:
Key Points Summary
| Key Point | Description |
| Stability | StickyAssignor maintains a stable partition distribution during normal operations. |
| Problematic Rebalancing | Can cause an uneven distribution during certain transient events such as consumers leaving or joining. |
| Cumbersome in Small Groups | More apparent in consumer groups with a partition count close to or less than the number of consumers. |
| Potential Solution | Monitoring and potentially adjusting the partition.assignment.strategy can mitigate issues. |
Subtopics for Enhancement
- Comparative Analysis: Comparison with other assignment strategies like
RangeorRoundRobin. - Consumer Group Health Monitoring: Tools and techniques to monitor and diagnose consumer group behavior.
- Advanced Configuration and Tuning: How to fine-tune the consumer configs for optimal partition distribution.
Conclusion
While the StickyAssignor provides benefits in maintaining consumer-partition affinity, its drawbacks particularly in corner cases where consumer count matches or exceeds partition count should be accounted for. A deeper understanding and careful monitoring are required to ensure efficient consumption of messages without sacrificing throughput or risking unassigned consumers.
Related reading
- kafka stop consuming message from new assigned partitions after rebalancing
- Kafka Storm Integration using Kafka Spout
- Kafka Storm Spout Got fetch request with offset out of range
- Kafka Stream - CommitFailedException Commit cannot be completed since the group has already rebalanced and assigned the partitions to another member
- Kafka Stream Exception GroupAuthorizationException
- Kafka stream PolicyViolationException Topic replication factor must be 3
- Kafka Stream aggregation with custom object data type
- Kafka Stream and KTable One-to-Many Relationship Join

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.