Pubudu
Pubudu

Reputation: 61

Weired Kafka Consumer Group Re-balancing

My kafka topic has two partitions and single kafka consumer. I have deployed my consumer application(spring kafka) in the AWS. In logs I see kafka consumer re-balance in time to time. This is not frequent. As per the current observation when consumer is listening to the topic and idle this re-balancing occurs. Appreciate if someone can explain me this behavior. I have posted some logs here.

[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Request joining group due to: group is already rebalancing
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] Revoke previously assigned partitions order-response-v3-qa-0, order-response-v3-qa-1
b2b-group: partitions revoked: [order-response-v3-qa-0, order-response-v3-qa-1
[Consumer clientId=consumer-b2b-group-1, groupId=b2b-group] (Re-)joining group

Upvotes: 2

Views: 5462

Answers (2)

Divya J
Divya J

Reputation: 495

Kafka starts a rebalancing if a consumer joins or leaves a group. Below are various reasons why that can or will happen.

A consumer joins a group:

  1. Application Start/Restart — If we deploy an application (or restart it), a new consumer joins the group
  2. Application scale-up — We are creating new pods/application

A consumer leaves a group:

  1. max.poll.interval.ms exceeded — polled records not processed in time session.timeout.ms exceeded — no heartbeats sent, likely because of an application crash or a network error
  2. Consumer shuts down
  3. Pod relocation — Kubernetes relocates pods sometimes, e.g. if nodes are removed via kubectl drain or the cluster is scaled down. The consumer shuts down (leaves the group) and is restarted again on another node (joins the group).
  4. Application scale-down

If you would like to understand more in depth. Here is one of the amazing article I have read

https://medium.com/bakdata/solving-my-weird-kafka-rebalancing-problems-c05e99535435

Upvotes: 1

Sandhya Ratan
Sandhya Ratan

Reputation: 26

Re-balancing is a feature that automatically optimizes uneven workloads as well as topology changes (e.g., adding or removing brokers). This is achieved via a background process that continuously checks a variety of metrics to determine if and when a to rebalance should occur. you can go through the below link for further knowledge:

https://medium.com/streamthoughts/apache-kafka-rebalance-protocol-or-the-magic-behind-your-streams-applications-e94baf68e4f2

Upvotes: 1

Related Questions