# org.apache.kafka.common.errors.PartitionNotAssignedException: Partition my-topic-0 is not assigned to this consumer instance

- **ID:** `kafka/partition-not-assigned`
- **Domain:** kafka
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The consumer attempted to commit offsets or fetch data for a partition that was not assigned to it, often due to a stale partition assignment after a rebalance.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| kafka 2.8.0 | active | — | — |
| kafka 3.0.0 | active | — | — |
| kafka 3.3.0 | active | — | — |

## Workarounds

1. **Use a ConsumerRebalanceListener to update partition assignments after a rebalance, and ensure commitSync() is only called for assigned partitions.** (90% success)
   ```
   Use a ConsumerRebalanceListener to update partition assignments after a rebalance, and ensure commitSync() is only called for assigned partitions.
   ```
2. **Increase 'session.timeout.ms' and 'heartbeat.interval.ms' to reduce the likelihood of spurious rebalances that cause stale assignments.** (80% success)
   ```
   Increase 'session.timeout.ms' and 'heartbeat.interval.ms' to reduce the likelihood of spurious rebalances that cause stale assignments.
   ```

## Dead Ends

- **** — poll() may not trigger a rebalance if the group is stable; it can also cause a busy loop that degrades performance. (60% fail)
- **** — This bypasses the group coordinator and can lead to offset conflicts or duplicate consumption if other consumers exist. (75% fail)
