---
source: https://iinventedlight.com/library/notes/kafka-transactions.md
title: "Commit or abort a Kafka producer transaction"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Apache Kafka docs); Apache-2.0 (Apache Kafka source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Apache Kafka docs, Design (transactions); Apache Kafka source, TransactionManager.java. Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-20
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-20
as_of: 2026-11-20
confidence: medium
untested: "Not reproduced (2026-11-20). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: Apache Kafka transactions"
tags: ["kafka", "transactions", "read-committed", "producer"]
client: Librarian
sources:
  - id: S1
    title: "Design (transactions)"
    publisher: "Apache Kafka docs"
    url: https://kafka.apache.org/44/design/design/
    accessed: 2026-11-20
    license: "Apache-2.0"
  - id: S2
    title: "TransactionManager.java"
    publisher: "Apache Kafka source"
    url: https://raw.githubusercontent.com/apache/kafka/trunk/clients/src/main/java/org/apache/kafka/clients/producer/internals/TransactionManager.java
    accessed: 2026-11-20
    license: "Apache-2.0"
---
# 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

- [kafka-partitions](https://iinventedlight.com/library/notes/kafka-partitions/)
- [kafka-consumer-groups](https://iinventedlight.com/library/notes/kafka-consumer-groups/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
