Kafka Transaction Failures
Transactions protect atomic writes and consume-transform-produce workflows. Do not turn a fatal transaction error into an unbounded retry loop.
Classify the Error
Section titled “Classify the Error”| Error | Meaning and action |
|---|---|
ProducerFencedException | Another producer owns the transactional ID; close this instance |
InvalidProducerEpochException | Producer session is stale; close and recreate after finding the ownership problem |
OutOfOrderSequenceException | Sequence/session invariant failed; treat as fatal when surfaced |
TransactionCoordinatorFencedException | Coordinator changed; let the client rediscover it |
CommitFailedException with offsets | Group generation/member epoch changed; abort, poll, and retry the processing loop |
| Transaction timeout | Work exceeded transaction.timeout.ms or coordinator/broker latency prevented completion |
Capture Evidence
Section titled “Capture Evidence”Record transactional ID, producer ID/epoch, client ID, group ID and member metadata, affected partitions, coordinator broker, complete exception chain, transaction duration, and deploy/failover timeline.
Check transaction abort/error metrics, coordinator requests, broker/controller health, ISR for transaction-state and output topics, and authorization on transactional IDs and topics.
Diagnose Fencing
Section titled “Diagnose Fencing”Search for two live instances using the same transactional.id, overlapping deployment generations, cloned configuration, or an orchestrator that starts a replacement before the old owner stops. Fencing during an intentional failover is expected; fencing during steady state is not.
Recover
Section titled “Recover”- Close a fenced or fatally failed producer.
- Stop the duplicate owner or correct transactional-ID allocation.
- Restore coordinator broker, topic ISR, network, or authorization.
- For a consume-transform-produce loop, abort the transaction, call
poll()to rejoin and obtain current group metadata, then retry from owned offsets. - Increase transaction timeout only when the business transaction legitimately requires it and broker bounds permit it.
Warning
Do not commit offsets outside the transaction as a shortcut. That breaks the atomic relationship between output records and consumed positions.
Kafka 4.4 Offset-Commit Behavior
Section titled “Kafka 4.4 Offset-Commit Behavior”Kafka 4.4 adds TxnOffsetCommit v6 with topic IDs and more precise group errors. Handle the returned error specifically. A stale generation or member epoch requires abort/rejoin, not a blind commit retry.
Verify
Section titled “Verify”Confirm a single producer owns each transactional ID, transactions commit within the expected duration, abort/fence rates return to baseline, read-committed consumers see only complete transactions, and offsets/output advance atomically.
Prevent Recurrence
Section titled “Prevent Recurrence”Derive transactional IDs from stable unique instance identities, make deployment handoff explicit, monitor transaction age/abort/error rates, and test coordinator and member failover.