Commit or abort a Kafka producer transaction
Answer: In Kafka, transactional producers and consumers are separate clients. Set isolation.level=read_committed and enable.auto.commit=false on the consumer. A read-committed consumer is given only committed messages.
Transactional producers and isolation
Transactions in Kafka work a bit differently than in other messaging systems, because the consumer and the producer are separate. The consumer must set isolation.level=read_committed and enable.auto.commit=false. Only the producer carries the transactional.id configuration.
Only committed messages are ever given out to the consumer. This is how the read-committed consumer does not see records from aborted transactions. It is important to handle exceptions and aborted transactions correctly. AbortableException is for exceptions that require transaction abort and reprocessing.
| transactional.id | isolation.level | |---|---| | producer configuration | read_committed | | enable.auto.commit | false | | aborted transactions | not given to read_committed |
Prepare and errors
The client code transitions the transaction to the PREPARED_TRANSACTION state and sets preparedTxnState with the current producer ID and epoch. That method is only for transactional producers. Idempotent producers have no concept of abortable errors. Recovery is the application's own strategy and must include restarting the producer.
See also
Claims
- id: C1 claim: Kafka transactions differ from transactions in other messaging systems. source: S1 evidence: "Kafka transactions are a bit different from transactions in other messaging systems."
- id: C2 claim: A read-committed consumer should also disable auto-commit. source: S1 evidence: "The consumer configuration must include isolation.level=read_committed and enable.auto.commit=false ."
- id: C3 claim: Preparing a transaction transitions it to the PREPARED_TRANSACTION state. source: S2 evidence: "This transitions the transaction to the PREPARED_TRANSACTION state."
Sources
- [S1] Design (transactions). Apache Kafka docs. https://kafka.apache.org/44/design/design/ . License: Apache-2.0. Accessed 2026-11-20.
- [S2] TransactionManager.java. Apache Kafka source. https://raw.githubusercontent.com/apache/kafka/trunk/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java . License: Apache-2.0. Accessed 2026-11-20.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Apache Kafka docs, Design (transactions); Apache Kafka source, TransactionManager.java. Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Apache Kafka docs, Design (transactions); Apache Kafka source, TransactionManager.java. Apache-2.0.
Cite this
iinventedlight. 2026. "Commit or abort a Kafka producer transaction." iinventedlight Library, iil:note:3y38g3he, version of 2026-11-20. https://iinventedlight.com/library/notes/kafka-transactions/. License: CC-BY-4.0.
@misc{iil_note_3y38g3he,
author = {{iinventedlight}},
title = {{Commit or abort a Kafka producer transaction}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-20},
url = {https://iinventedlight.com/library/notes/kafka-transactions/},
note = {Permanent ID iil:note:3y38g3he. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- kafka-transactions.table.json (table; CC-BY-4.0)
- kafka-transactions.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kafka-transactions.md.