Crash after the write
A worker writes dispatch D1, crashes before committing its input position, reprocesses D1, then receives genuine dispatch D2.
The interview prompt
A worker writes dispatch D1, crashes before committing its input position, reprocesses D1, then receives genuine dispatch D2. Design retries that leave six copies shipped and one customer notification per eligible dispatch.
Draw the crash at three places
Before the destination write, retry must perform the write. After the write but before saving input progress, retry must recognize the same business occurrence and leave the destination unchanged. After progress is saved, the output must already be durable. Put those three checkpoints on the board and specify what is atomic at each one.
For a SQL destination, a unique (source, dispatch ID) can protect an insert. If a running total is updated separately, the unique insert and increment must commit or roll back together, and the increment must occur only for a newly accepted event. Deriving totals from the deduplicated fact table avoids that extra mutable state at the cost of additional reads. If the event source supports later corrections, make version handling explicit before treating duplicate IDs as final.
Sending a notification crosses a second boundary. Record an outbox item in the same transaction as the accepted event, then send it using a stable delivery key if the recipient API supports idempotency. A crash after successful delivery but before acknowledgment still leaves an ambiguous outcome without that recipient guarantee. State the delivery semantics you can actually offer.
The model behind the answer
The worker adds four shipped units to Saturday’s total, then crashes before saving its input position. On restart, the same dispatch arrives again. A second increment would turn four physical books into eight reported books. Saving the position first simply moves the failure window to the other side of the write.
One design stores the dispatch under a stable unique event ID in the destination and derives totals from that table. Another atomically records the event ID and updates the aggregate in the same destination transaction. In either design, a retry has the same observable effect as one successful write. A separately maintained “seen IDs” cache needs its own consistency and retention story.
A checkpoint records recoverable progress and associated state. A replay rebuilds from retained input. To make an “exactly once” claim, name the destination included in the guarantee. If the job also sends a shipping email, that side effect needs its own deduplication agreement. Apache Kafka on delivery semantics
Try it in SQLite
Replay a dispatch and apply a correction
The inbox contains four messages for two occurrences. A retry repeats a version. A correction changes D2 from three to two copies. The corrected-total example assumes identical payloads for repeated versions. The conflict review introduces a producer violation. To challenge certification, insert another D2/version 2 row with 9 units and a new sequence number before the certification query. The fixture assumes non-null units and one source.
Tables and sample data
Each run starts with fresh sample data. Use Ctrl+Enter or ⌘+Enter to run. Only your browser processes the query.
Verify the effect outside the worker
Ask the agent for a retryable destination write and a notification outbox. The reviewer controls a fake recipient. Make it accept a notification, drop the acknowledgment, then restart the sender. Count actual accepted notifications at the recipient as well as rows in the outbox.
Reviewer decision. One outbox row can still produce two deliveries. With receiver-side deduplication on a stable key, two attempts should produce one accepted effect. Without that capability, record the ambiguous delivery and agree how to reconcile it. In the browser lab, try Certify the replay total. With matching retries it returns five corrected units. With conflicting quantities under D2 version 2 it withholds the total. The fake recipient tests a separate delivery guarantee.
Further reading. Designing Data-Intensive Applications, 2nd ed., on the boundary of checkpointing when output reaches an external system.
One more question
You retained seen-event IDs for 24 hours but replay a month of input. What happens?
Check your reasoning
Older retries can be accepted again. Anchor deduplication in durable fact identities or retain state for the full replay horizon. Test a month-end backfill against a saved baseline, including a genuine source correction that should change the total.
Previous · Choose what the source must retain · Next · Decide when yesterday can change · Complete series map