What's Actually Happening

Kafka consumer group constantly rebalances, causing consumers to repeatedly leave and rejoin the group.

The Error You'll See

bash
# Consumer logs:
Revoking previously assigned partitions
Joining group
Successfully synced group
Rebalance failed and re-joining group

Why This Happens

  1. 1.Processing too slow - Exceeds max.poll.interval
  2. 2.Session timeout short - Heartbeat missed
  3. 3.Consumer overloaded - Cannot keep up
  4. 4.GC pauses - Long garbage collection
  5. 5.Network issues - Intermittent connectivity

Step 1: Increase Timeouts

properties
# Consumer config:
max.poll.interval.ms=600000
session.timeout.ms=30000
heartbeat.interval.ms=10000

Step 2: Reduce Batch Size

properties
max.poll.records=100
fetch.max.bytes=1048576

Step 3: Monitor Rebalances

```bash # Check consumer group: kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group mygroup

# Check metrics: kafka_consumer_group_rebalance_rate ```

Kafka Rebalance Checklist

CheckSettingExpected
max.poll.interval>= processing timeAdequate
session.timeout> heartbeat*3Sufficient
processing rate< produce rateKeeping up

Verify the Fix

bash
# No frequent rebalances in logs
# Stable partition assignment
# Consumers remain in group
  • [Fix Kafka Consumer Lag](/articles/fix-kafka-consumer-lag)
  • [Fix Kafka Broker Unavailable](/articles/fix-kafka-broker-unavailable)