What's Actually Happening
Kafka consumer group constantly rebalances, causing consumers to repeatedly leave and rejoin the group.
The Error You'll See
# Consumer logs:
Revoking previously assigned partitions
Joining group
Successfully synced group
Rebalance failed and re-joining groupWhy This Happens
- 1.Processing too slow - Exceeds max.poll.interval
- 2.Session timeout short - Heartbeat missed
- 3.Consumer overloaded - Cannot keep up
- 4.GC pauses - Long garbage collection
- 5.Network issues - Intermittent connectivity
Step 1: Increase Timeouts
# Consumer config:
max.poll.interval.ms=600000
session.timeout.ms=30000
heartbeat.interval.ms=10000Step 2: Reduce Batch Size
max.poll.records=100
fetch.max.bytes=1048576Step 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
| Check | Setting | Expected |
|---|---|---|
| max.poll.interval | >= processing time | Adequate |
| session.timeout | > heartbeat*3 | Sufficient |
| processing rate | < produce rate | Keeping up |
Verify the Fix
# No frequent rebalances in logs
# Stable partition assignment
# Consumers remain in groupRelated Issues
- [Fix Kafka Consumer Lag](/articles/fix-kafka-consumer-lag)
- [Fix Kafka Broker Unavailable](/articles/fix-kafka-broker-unavailable)