# org.apache.kafka.common.errors.RebalanceInProgressException: The group is rebalancing, so a rebalance is already in progress.

- **ID:** `kafka/group-rebalance-timeout`
- **Domain:** kafka
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

A consumer request (like offset commit or join group) was made while a consumer group rebalance was already in progress, causing the request to be rejected.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Kafka 2.8.0 | active | — | — |
| Kafka 3.0.0 | active | — | — |
| Kafka 3.4.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |

## Workarounds

1. **Increase max.poll.interval.ms to allow more time for processing between polls, reducing the chance of rebalance being triggered:

Properties props = new Properties();
props.put("max.poll.interval.ms", 600000);  // 10 minutes
props.put("max.poll.records", 500);  // Fewer records per poll

And ensure the consumer processes records quickly or uses async processing.** (80% success)
   ```
   Increase max.poll.interval.ms to allow more time for processing between polls, reducing the chance of rebalance being triggered:

Properties props = new Properties();
props.put("max.poll.interval.ms", 600000);  // 10 minutes
props.put("max.poll.records", 500);  // Fewer records per poll

And ensure the consumer processes records quickly or uses async processing.
   ```
2. **Handle RebalanceInProgressException in the consumer loop by catching the exception and retrying after a short delay:

try {
    consumer.commitSync();
} catch (RebalanceInProgressException e) {
    // Wait for rebalance to complete
    Thread.sleep(1000);
    consumer.poll(Duration.ofSeconds(1));  // Trigger rebalance join
    consumer.commitSync();
}** (75% success)
   ```
   Handle RebalanceInProgressException in the consumer loop by catching the exception and retrying after a short delay:

try {
    consumer.commitSync();
} catch (RebalanceInProgressException e) {
    // Wait for rebalance to complete
    Thread.sleep(1000);
    consumer.poll(Duration.ofSeconds(1));  // Trigger rebalance join
    consumer.commitSync();
}
   ```

## Dead Ends

- **Increase the session.timeout.ms to a very high value** — Session timeout controls heartbeat detection, not rebalance duration; a high value may delay failure detection but does not prevent rebalance conflicts. (80% fail)
- **Set the consumer to use static group membership** — Static membership reduces rebalance frequency but does not eliminate it; rebalance can still be triggered by coordinator changes or partition reassignments. (70% fail)
