← All notes

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

Sources

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

Permanent ID: iil:note:3y38g3he

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.},
}

Markdown

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.

All artifact files (JSON index)

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.