Video in progress

On prod, a consumer group rebalances every few minutes. How do you investigate?

INFO  [Consumer clientId=consumer-billing-3] Member consumer-billing-3-9f2c sending LeaveGroup
      request to coordinator ... due to consumer poll timeout has expired.
INFO  [Consumer clientId=consumer-billing-1] Request joining group due to: group is already rebalancing
WARN  Revoking previously assigned partitions [payments-4, payments-5]

First I find out who is starting the rebalance: is the consumer leaving on its own (poll interval exceeded), are heartbeats not arriving (session timeout, GC), or are pods restarting. The logs, the consumer metrics and the group coordinator logs on the broker give the answer.

📖 Answer

This log states the cause: "consumer poll timeout has expired", meaning max.poll.interval.ms was exceeded. When it isn't this clear, I go through it in this order.

  1. Who is leaving, and why. In the consumer logs I search for LeaveGroup, poll timeout, heartbeat, session timed out. On the broker side, the coordinator log says "Member ... has failed, removing it from the group", which is a session timeout.

  2. If it's a poll timeout. The batch processing is slow. I measure the number of records per poll and the processing time of each record. Often the cause is an external service that slowed down, has a 30s timeout, and you have 500 records × a slow call. The fix: lower max.poll.records, shorten the timeouts, add a circuit breaker.

  3. If it's a session timeout. The heartbeat thread couldn't run either, which means the whole JVM stalled. I look at the GC logs: a long Full GC, or container CPU throttling (container_cpu_cfs_throttled_seconds_total). If the memory limit is close, an OOMKill and restart.

  4. Deploys and autoscaling. If the HPA changes the pod count often based on lag, every change is a rebalance. A stabilization window, a cooperative assignor and static membership help here.

  5. The rebalance itself is long. If there's heavy work inside onPartitionsRevoked (clearing a cache, a synchronous commit to an external system), the rebalance stretches and the other consumers hit timeouts too.

For permanent monitoring I put the consumer metrics rebalance-rate-per-hour and last-rebalance-seconds-ago on the dashboard.