Monedula

Scenario 11.1.5 · Redpanda: exactly-once on Cloud Topics

Redpanda Kafka transactions: exactly-once on Cloud Topics

Diskless · Advanced · about 4 min · Apache Kafka 4.4 · Redpanda

Redpanda v26.2.2 Cloud Topics · a transactional producer commits one transaction on two partitions and aborts the next; the data goes through L0 objects and placeholders, read_committed reads only the committed records, and the reconciler leaves the aborted ones out of L1.

Run this scenario in the playground

After reconciliation the L1 object holds no aborted records. t+3.990s

broker-2's reconciler run started at 3350 ms, 2 s after the first placeholder and after the abort, so the LSO was already 2. It took offsets 0 and 1 of both partitions and at 3990 ms registered L1 object l1-0001: order-1 and order-2 are in it, the aborted order-3 and order-4 at offset 1 are left out. The LRO of both partitions moved to 1, covering the aborted offset. l0-0002 still holds the aborted records in S3 until L0 garbage collection, which needs 12 h.

Open at this step: step 5, After reconciliation the L1 object holds no aborted records

What you start with

Redpanda Cloud Topics keep each partition's Raft log, and transactions and idempotence ride on it: the partition checks the producer id, epoch and sequence on each placeholder, and commit and abort markers go into the Raft log as they are, with no upload. So exactly-once works on data that lives in S3. Producer tx (transactional.id tx-app, az-a) writes order-1 to orders-1 and order-2 to orders-4, both led by broker-2 in az-b, and commits; then it writes order-3 and order-4 and aborts. Group g-rc (az-b) reads with isolation.level=read_committed. The same commit and abort on classic Kafka is scenario 04.2.1. Timings are slowed so each phase gets its own frame.

Step by step

  1. A transaction writes to two partitions; data goes through L0 t+1.350s tx began a transaction at 100 ms and sent order-1 and order-2 at 200 ms, to orders-1 and orders-4, both led by broker-2. Both records went into broker-2's L0 buffer and one L0 object, l0-0001, which uploaded to S3 from 750 to 1350 ms. Only now are the placeholders appended to the two Raft logs, at offset 0, and the transaction is open from there: the LSO of both partitions stays at 0. tx asked to commit at 900 ms, during the upload; the commit is still waiting for its records to be acked. Open at this step: step 1, A transaction writes to two partitions; data goes through L0
  2. Commit waits for the records to be acked; the markers need no upload t+1.700s The placeholders reached the followers at 1650 ms: a majority holds offset 0 on both partitions, the high watermark moved to 1 and tx got both acks. From 1650 to 1700 ms the high watermark was 1 and the LSO still 0. The commit, waiting since 900 ms, ended at 1700 ms, the simulator's next 50 ms check after the acks, and the LSO moved to 1 on both partitions. Redpanda appends the commit markers to each partition's Raft log as they are, with no L0 object; the simulator draws them as in every simulator transaction, without an offset, so the high watermark stays at 1. Open at this step: step 2, Commit waits for the records to be acked; the markers need no upload
  3. read_committed sees the committed records t+1.800s c-rc polled at 1800 ms and read order-1 and order-2, offset 0 of each partition, from broker-2's batch cache, filled when the placeholders were appended. Its read stops at the LSO, 1. tx began its second transaction at 1750 ms: order-3 and order-4 now sit in broker-2's L0 buffer, bound for L0 object l0-0002, with no offset yet. Open at this step: step 3, read_committed sees the committed records
  4. The next transaction is aborted t+3.600s l0-0002 uploaded from 2300 to 2900 ms; the placeholders took offset 1 on both partitions and were acked at 3200 ms. tx asked to abort at 2700 ms, during the upload: like the commit, the abort waited for the records already in L0 to be acked, and it ended at 3250 ms. Offset 1 of both partitions is now an aborted range and the LSO moved to 2. c-rc's poll at 3600 ms stepped its position over offset 1, returned no record and read no object. On Redpanda the abort markers go into the Raft logs too; in the simulator they take no offset. Open at this step: step 4, The next transaction is aborted
  5. After reconciliation the L1 object holds no aborted records t+3.990s broker-2's reconciler run started at 3350 ms, 2 s after the first placeholder and after the abort, so the LSO was already 2. It took offsets 0 and 1 of both partitions and at 3990 ms registered L1 object l1-0001: order-1 and order-2 are in it, the aborted order-3 and order-4 at offset 1 are left out. The LRO of both partitions moved to 1, covering the aborted offset. l0-0002 still holds the aborted records in S3 until L0 garbage collection, which needs 12 h. Open at this step: step 5, After reconciliation the L1 object holds no aborted records

The takeaway

tx's first transaction put order-1 and order-2 into L0 object l0-0001; they got offset 0 only when their placeholders were appended, and the commit, asked for during the upload, waited until both were acked before the LSO moved past them, so g-rc read them. The second transaction's records went the same way through l0-0002, and the abort marked offset 1 aborted: g-rc stepped over it without reading an object, and broker-2's reconciler wrote L1 object l1-0001 with only the committed records, moving the LRO to 1, covering the aborted offset. Redpanda v26.2.2 facts: transactions and idempotence ride on the partition's Raft log, so they work on data in S3; the partition checks the producer id, epoch and sequence on each placeholder; commit and abort markers go into the Raft log as they are, with no upload; the reconciler reads from the LRO + 1 to the last stable offset through a read_committed reader, so aborted records are left out of L1; and an L0 object is deleted only once it is reconciled and at least 12 h old, so l0-0002 still holds the aborted records in S3 at the end. Simulator choices: the commit and the abort wait for the transaction's records to be acked and check every 50 ms, so each ended 50 ms after its acks; then the simulator's classic marker model applies: the markers take no offset, while Redpanda writes them to the Raft log with offsets, so on Redpanda order-3 and order-4 would sit after the commit marker; the transaction coordinator is drawn as classic Kafka's; the reconciler runs every 2 s (Redpanda adapts the interval between 250 ms and 10 s), so its first run, 2 s after the first placeholder, came after the abort and one L1 object covers both transactions; the new LRO takes effect in the tick the L1 object is registered; and the buffer interval, the upload and the L1 registration are slowed to 500 ms, 600 ms and 40 ms.

Configs in this scenario

  • transactional.id A stable name that turns on transactions for a producer (and implies idempotence); a new producer that calls initTransactions() with the same id fences the older one.
  • isolation.level read_uncommitted (the default) returns every record, including those of open and aborted transactions; read_committed returns only committed transactional records and stops at the last stable offset. How isolation.level works

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=11.1.5" title="Kafka Simulator: Redpanda: exactly-once on Cloud Topics" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/redpanda-exactly-once-cloud-topics/">Redpanda Kafka transactions: exactly-once on Cloud Topics</a></p>

Further reading

Redpanda v26.2.2 source on GitHub

More in Diskless

All scenarios