Unit 3 of 15 · about 4 hours · explain, derive
Producer acknowledgements, idempotent sequence state and transactional scope
Retried requests are certain and ambiguous outcomes are permanent: a timeout never says whether the write landed. Acknowledgements, sequence state and transactions are the three tools that make retries safe.
You'll be able to
- Explain
acks0, 1 and all as durability versus latency choices gated bymin.insync.replicas. - Explain the idempotent producer's per-partition sequence state and what breaks duplicate suppression.
- Derive the atomic scope of a Kafka transaction: which partition writes and offsets commit together, and what stays outside it.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Delivery semantics and transactionsApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols
Message Delivery Semantics (at-most, at-least and exactly-once; idempotent producer with producer ID and sequence numbers); Using Transactions (offsets atomic with output;
isolation.level=read_committedwithenable.auto.commit=falseandtransactional.id) - Server-side transaction defenseApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols
Overview: KIP-890 Transactions Server Side Defense, generally available since 4.0, with a producer epoch bump per transaction
Read the Overview only. Skip Upgrade and Downgrade and Performance unless you run a multi-version setup.
- Atomic commit scope in stream processorsDDIA 2e - Chapters 11 to 13 Batch and Stream Processing
Chapter 12, Atomic commit revisited (pp. 527 to 528): internal transactions in Dataflow, VoltDB and Kafka; overhead amortized over several input messages per transaction
Focus on
acks=0never waits,acks=1waits for the leader only, andacks=allwaits for all current in-sync replicas, further gated bymin.insync.replicas. Without that gate the ISR can shrink to the leader andallmeans the leader only.- Idempotence keys each retried batch by producer ID plus per-partition sequence numbers, so a batch the broker already wrote is acknowledged without a second append. It is per partition and holds only while the broker retains that producer's sequence state.
- A transaction commits a set of partition writes plus consumer offsets atomically, readable under
read_committed. Anything outside Kafka, such as a database write or an email, is not in that atomic scope. - Timeout ambiguity remains: a producer that times out cannot tell a lost request from a lost reply, so it must retry and let deduplication or the transaction decide.
Common mistakes · 3
- Calling
acks=allalone durable. Withoutmin.insync.replicasthe ISR can shrink to the leader, soallmeans the leader only. - Expecting transactions to cover external effects. The atomic scope ends at Kafka partition writes plus offsets.
- Using
kafka-console-producer.shto test transactions. It cannot run transactions; use client code.
Try it yourself
Closed-book, before checking anything
acks and min.insync.replicas settings that lose an acknowledged write when the leader dies, and the settings that refuse the write instead, and state the read rule that hides aborted transactions.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.With
acks=1, the leader acknowledges a write and dies before replicating it. Is the write lost?AnswerYes. Only the leader held it, so the acknowledgement promised nothing about replication.
2.With
min.insync.replicas=2and an ISR of just the leader, what does anacks=allwrite return?AnswerAn error refusing the write until the ISR recovers. The broker rejects instead of silently weakening durability.
3.A batch times out and the producer retries with the same sequence number. The broker already appended it. What happens?Answer
The broker detects the duplicate sequence and acknowledges without appending again, so the retry is safe.
4.A transaction writes partitions A and B plus offsets, then aborts. What does a
read_committedconsumer see?AnswerNothing from that transaction:
read_committedskips its aborted records. The consumer offsets written in the transaction never take effect either, so the input records are read and processed again.
You're done when
You can predict the fate of a write for each acks value under leader death, and draw the exact boundary of a transaction's atomic scope.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 16 more in the section
- DDIA 2e - Chapters 11 to 13 Batch and Stream ProcessingMartin Kleppmann and Chris Riccomini · primary
Read batch processing, stream processing and the streaming-systems philosophy in order. For every guarantee, mark the source position, operator state, output effect and recovery boundary it actually covers.
- Apache Kafka 4.3 - Design, Log, Rebalance and Transaction ProtocolsApache Kafka · required
Read the 4.3 design page (replication and in-sync replicas, acknowledgements and
min.insync.replicas, delivery semantics, idempotence and transactions, the consumer, log compaction), the log implementation page, and the consumer rebalance protocol and transaction protocol pages (https://kafka.apache.org/43/operations/). Kafka 4.0 removed ZooKeeper. Run experiments in theapache/kafka:4.3.1image and compare each contract with your mini log.
Also in this section
- The Log: What Every Software Engineer Should Know About Real-time Data's Unifying Abstraction (Kreps, 2013)LinkedIn Engineering · support
Read it first as the short concept spine for logs, replicas, data integration and stream processing, before DDIA 2e Chapters 11 to 13.
- Kafka: a Distributed Messaging System for Log Processing (Kreps, Narkhede and Rao, 2011)NetDB workshop (mirror) · support
Read it as the design ancestor of your mini log: segments, offsets, pull consumers and consumer groups. Replication is future work in this paper, so take durability from the current docs.
- The Dataflow Model (Akidau et al., 2015)Google (author copy) · required
Read the model section: event time versus processing time, windowing, triggers and accumulation. Implement one trigger and one accumulation mode, not the catalog.
- MillWheel: Fault-Tolerant Stream Processing at Internet Scale (Akidau et al., 2013)PVLDB · support
Read low watermarks, persistent state, strong productions and exactly-once delivery by deduplication. The deduplication holds only within its retention bound.
- Lightweight Asynchronous Snapshots for Distributed Dataflows (Carbone et al., 2015)arXiv · required
Read the asynchronous barrier snapshotting algorithm for acyclic graphs and its recovery; skip the cyclic extension. Barriers assume FIFO channels.
- Distributed Snapshots: Determining Global States of Distributed Systems (Chandy and Lamport, 1985)Leslie Lamport · support
Read the marker-sending and marker-receiving rules and why the recorded state is consistent. The algorithm needs FIFO channels.
- Gossip Glomers - Kafka-Style LogFly.io and Jepsen · required
Each challenge runs locally under Maelstrom (v0.2.4; the pages were tested on 0.2.3) with its checker and, where the page says so, the partition nemesis; keep the run directory as the history. Do 5a to 5c:
send,poll,commit_offsetsandlist_committed_offsetson one node, then two nodes overlin-kv, then with fewer messages. The checker catches lost writes and nonmonotonic or skipped offsets; it does not check recency or exactly-once effects. - AWS Builders' Library - Avoiding Insurmountable Queue BacklogsAmazon Web Services · support
Read it for how backlogs grow and why they take long to drain, and for backpressure, prioritization, sidelining and constant work. Compare its recovery strategies with the bounded backlog and lag measurements of your consumer.
- Apache Flink 2.3 - Event Time, State and CheckpointingApache Flink · required
Read the 2.3 concepts pages on time (event time, watermarks, lateness, windowing) and stateful stream processing (keyed state, checkpoint barriers, recovery, unaligned checkpoints, exactly-once versus at-least-once), then the watermark-generation guide on idle sources. Use them to build one bounded local processor; exactly-once covers state and participating sinks only.
- Confluent Schema Registry - Schema Evolution and CompatibilityConfluent · support
Use only the compatibility-type definitions (backward, forward, full and their transitive forms) as the vocabulary for your schema checks, with the Avro schema resolution rules as the mechanism.
- HLD Handbook - Queues, Streaming, Stream vs Batch and CDCHLD Handbook · required
Read only Part 2 message queues and pub-sub plus Part 4 stream versus batch and change data capture. Use Part 5 event-driven architecture after the underlying log and replay contract is clear.
- MIT 6.5840 - Lab 1 MapReduceMIT PDOS · support
Complete or review the coordinator and worker lab to connect deterministic batch dataflow, task retries and output publication. Do not confuse its shared-filesystem assumptions with the durable log contract.
- Replicated Log and Stream Processor - Full Data PathRoadmap-Final · support
Complete partitioned log, producer identity, consumer ownership, offsets, backpressure, event-time state, checkpoint, replay and sink boundary. Run the required producer, consumer, storage and late-data fault campaign.
- Apache Iceberg - Table SpecificationApache Iceberg · reference
Read the snapshot, manifest list and manifest sections for the read path, and the table metadata section for the atomic metadata-file swap that commits a snapshot.
- Delta Lake Protocol (pinned commit)Delta Lake · reference
Read the transaction log replay and checkpoint sections for how readers reconstruct table state, and the concurrency section for the optimistic commit rule.
- Apache Avro 1.12.0 Specification - Schema ResolutionApache Avro · reference
Read Schema Resolution only: records match by field name, writer-only fields are ignored, reader-only fields are filled from defaults, plus the promotion rules.