Skip to content
Veltoryx Technologies
ProLesson 5.3Intermediate6 min readUpdated 31 October 2026

Kafka Transactions & Read-Process-Write

Explore the internal 2-phase commit protocol of Kafka transactions, the Transaction Coordinator, zombie fencing, and read_committed isolation.

The most common architectural pattern in event-driven stream processing is the Read-Process-Write loop: an application reads an incoming event from Topic A, applies business transformations, produces one or more output events to Topic B, and commits its input offset to __consumer_offsets.

If the application crashes midway through this cycle—after producing to Topic B but before committing the input offset—the replacement instance will re-read the original event and produce a duplicate output record to Topic B.

Apache Kafka solves this with Kafka Transactions (KIP-98), enabling atomic multi-partition writes where output records and consumer offsets commit together in a single atomic transaction.

In this lesson, you will trace the internal mechanics of Kafka's 2-phase commit protocol, understand the Transaction Coordinator, and learn how isolation.level=read_committed prevents dirty reads.

01The Problem: Partial Failures in Stream Processing

Consider a payment processing microservice:

text
[Input: "orders"] -> [ShopFlow Payment Engine] -> [Output: "payments"]
                                              -> [Offsets: "__consumer_offsets"]

Without transactions, producing output records and committing consumer offsets are two separate network operations:

  1. Application reads OrderPlaced at offset 100.
  2. Application produces PaymentDebited to the payments topic. The broker writes it to disk.
  3. Before the application can commit offset 100 to __consumer_offsets, the host server loses power.
  4. When the service restarts, the consumer re-reads OrderPlaced at offset 100 and sends a second PaymentDebited record to the payments topic.

The downstream banking gateway now processes two debits for a single order.

Kafka Transactions: The Read-Process-Write Loop
Fig. 1 · Kafka Transactions: The Read-Process-Write Loop

Loading the rest of the lesson…