Kafka Group Coordinator (broker) quản lý consumer group lifecycle và partition assignment.
- Khi consumer join group, Group Coordinator trigger rebalance và chọn một consumer làm Group Leader — Leader thực hiện partition assignment theo strategy đã cấu hình và gửi kết quả về Coordinator. RangeAssignor (default): assign partition liên tiếp theo topic — consumer 0 nhận partition 0,1; consumer 1 nhận 2,3.
- Nếu partition không chia đều, consumer đầu tiên nhận nhiều hơn (uneven distribution across topics). RoundRobinAssignor: phân phối đều hơn bằng cách xen kẽ — mỗi consumer nhận partition luân phiên. StickyAssignor: cố gắng minimize sự thay đổi so với assignment trước. CooperativeStickyAssignor: như Sticky nhưng dùng cooperative protocol (không stop-the-world) — khuyến nghị cho ứng dụng mới theo KIP-429.
- Thực tế: số consumer không nên vượt số partition — consumer thừa sẽ idle.
- Khi scale out, thêm partition TRƯỚC khi thêm consumer để tránh idle consumers.
The Kafka Group Coordinator (a broker) manages the consumer group lifecycle and partition assignment.
- When a consumer joins a group, the Group Coordinator triggers a rebalance and elects one consumer as the Group Leader — the leader performs the partition assignment according to the configured strategy and sends the result back to the Coordinator. RangeAssignor (default): assigns consecutive partitions per topic — consumer 0 gets partitions 0,1; consumer 1 gets 2,3.
- If partitions don't divide evenly, the first consumer gets more (uneven distribution across topics). RoundRobinAssignor: distributes more evenly by interleaving — each consumer receives partitions in round-robin order. StickyAssignor: minimizes changes relative to the previous assignment. CooperativeStickyAssignor: like Sticky but uses the cooperative protocol (no stop-the-world) — recommended for new applications per KIP-429.
- In practice: do not let the number of consumers exceed the number of partitions — excess consumers sit idle.
- When scaling out, add partitions BEFORE adding consumers to avoid idle consumers.