Nâng CaoKafka iconKafka

Consumer rebalancing trong Kafka: vấn đề gì có thể xảy ra và cách tối ưu?

Rebalancing xảy ra khi consumer group thay đổi (thêm/xóa consumer, consumer crash, hoặc subscription thay đổi).

  • Trong quá trình rebalance, toàn bộ group dừng consume (stop-the-world), có thể gây latency spike.
  • Vấn đề phổ biến: session.timeout.ms quá ngắn → consumer bị kick ra group vì GC pause dài; max.poll.interval.ms quá ngắn → consumer xử lý lâu bị coi là dead.
  • Tối ưu: tăng session.timeout.msheartbeat.interval.ms, giảm max.poll.records, dùng incremental cooperative rebalancing (partition.assignment.strategy=CooperativeStickyAssignor) thay vì eager rebalancing — chỉ revoke partition thực sự cần chuyển, không dừng toàn bộ group.
  • Static group membership (group.instance.id) giúp tránh rebalance khi restart consumer (reuse partition assignment cũ trong vòng session.timeout.ms).

Xem toàn bộ Kafka cùng filter theo level & chủ đề con.

Mở danh sách Kafka