# org.apache.kafka.common.errors.TransactionalCoordinatorFencedException: The transactional coordinator with epoch 5 has been fenced

- **ID:** `kafka/transaction-coordinator-fenced`
- **Domain:** kafka
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A new transactional coordinator has taken over, fencing the old coordinator due to leader election or broker failure.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| kafka 3.5.0 | active | — | — |
| kafka 3.6.2 | active | — | — |
| kafka 3.7.0 | active | — | — |

## Workarounds

1. **Restart the transactional producer to re-initialize the coordinator connection: 'producer.initTransactions();' in code, or restart the application.** (90% success)
   ```
   Restart the transactional producer to re-initialize the coordinator connection: 'producer.initTransactions();' in code, or restart the application.
   ```
2. **Ensure all brokers have consistent transaction.state.log.replication.factor and min.insync.replicas settings, then restart the broker with the highest epoch: 'bin/kafka-server-stop.sh && bin/kafka-server-start.sh config/server.properties'** (75% success)
   ```
   Ensure all brokers have consistent transaction.state.log.replication.factor and min.insync.replicas settings, then restart the broker with the highest epoch: 'bin/kafka-server-stop.sh && bin/kafka-server-start.sh config/server.properties'
   ```

## Dead Ends

- **** — Manually reassigning partitions without checking coordinator health causes repeated fencing. (85% fail)
- **** — Disabling idempotent producer to avoid fencing breaks exactly-once semantics and may cause duplicates. (70% fail)
