Unit 5 of 15 · about 4 hours · derive

Offset commits versus application state and at-most-once, at-least-once and effectively-once delivery

Delivery labels describe where the offset moves relative to the work, not magic in the transport. The same broker gives all three semantics depending on when the consumer commits.

You'll be able to

  • Derive at-most-once, at-least-once and effectively-once from the order of processing, effect publication and offset commit.
  • Enumerate the crash windows between read, state update, output and offset commit, and state the valid recovery for each.
  • State an effectively-once effect contract with its atomic boundary and retention bound.

Covers

Offset commit versus application stateAt-most-once deliveryAt-least-once deliveryEffectively-once effect contract
1

Read

In this order, only the parts listed

0 of 3 done

  1. Fault tolerance: scope, atomic commit and idempotenceDDIA 2e - Chapters 11 to 13 Batch and Stream Processing

    Chapter 12, Fault Tolerance (pp. 526 to 528): microbatching and checkpointing cover state inside the framework only; Atomic commit revisited (effects plus offsets atomically); Idempotence (offset-keyed writes, determinism and fencing assumptions)

  2. Message delivery semanticsApache Kafka 4.3 - Design, Log, Rebalance and Transaction Protocols

    Message Delivery Semantics: at-most, at-least and exactly-once definitions with the producer-timeout ambiguity

  3. Exactly-once as at-least-once plus idempotenceHLD Handbook - Queues, Streaming, Stream vs Batch and CDC

    The Two Generals framing through the Kafka idempotent and transactional producer sections

    Review after the DDIA items. Treat its deployment numbers as reported figures from their era, not targets.

2

Focus on

  • Commit-before-process loses on crash, which is at most once. Process-before-commit duplicates on crash, which is at least once. The order of two operations decides the label.
  • Effectively-once needs the effect and the offset, or a dedup key, in one atomic boundary: a transaction or an idempotent write keyed by offset.
  • Idempotent replay needs deterministic processing, same-order replay, no concurrent writer, and dedup state retained past the retry horizon.
  • Storing the triggering offset with the value, as in Storm Trident, turns already-applied detection into a local read.
Common mistakes · 3
  • Claiming exactly-once from checkpointing alone. Output that left the processor before the crash cannot be recalled.
  • Committing offsets on a timer and calling redelivery impossible. Async commit widens the at-least-once window instead of closing it.
  • Keeping dedup keys forever or dropping them early. Unbounded state grows; short retention re-accepts old duplicates past the horizon.
3

Try it yourself

Closed-book, before checking anything

Closed-book, list the four crash windows for read, state update, external write and offset commit, and give the recovery behavior that each commit ordering forces.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.A consumer commits position 11, past record 10, then crashes before processing record 10. What happens to record 10?Answer

    It is lost to the group: the next owner resumes at 11. The commit claimed progress the consumer never made, which is at-most-once behavior.

  2. 2.A consumer writes a database row, crashes before committing the offset, and restarts. What does it see, and what prevents a duplicate row?Answer

    It redelivers the record. Only an idempotent write, such as the offset stored with the row in one atomic boundary, prevents the duplicate.

  3. 3.At-least-once delivery plus an idempotent consumer equals what, and with which boundary?Answer

    Effectively-once effects within the dedup retention bound and inside systems the consumer controls. An external RPC or second database write outside the boundary breaks it.

  4. 4.Two processors concurrently write offset-stamped values for the same key. Is the result idempotent?Answer

    No. Concurrent writers interleave, so the last write need not carry the highest offset. Idempotent replay needs a single writer or fencing.

5

Practice

  • AlgoMaster: Build an Idempotent Consumer

    process returns true once per message ID and false on every redelivery; per-object dedup state

    The judge tests one object with no crashes. Add a TTL on the ID set and a crash-restart test in the mini-project to make the retention bound real.

  • AlgoMaster: Deduplicate Idempotent Requests

    execute stores the first result per key and replays it on retries; keys are case-sensitive

    The judge keeps entries for the object lifetime. Decide the production retention bound separately, since retries past it execute twice.

You're done when

You can label any commit ordering with its delivery semantics, draw its crash windows, and state the atomic boundary behind each effectively-once claim.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 15 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 the apache/kafka:4.3.1 image and compare each contract with your mini log.

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

Also in this section