Q10 · How do you design for exactly-once or effectively-once processing guarantees?

Back to 24 Architecture Questions.

The question is not a broker feature comparison. The axis it turns on: which side of the effect is deduplicated, the write or the delivery. Exactly-once delivery is not a thing anyone can sell you: retries, rebalances, and crashes make redelivery certain. Exactly-once effects are a thing you can build: at-least-once delivery, plus a guard in front of every write.

Guard at the write, not the delivery A broker delivers a message twice. The consumer's guard at the effect recognizes the duplicate and the side effect is written once. FIGURE 10 GUARD AT THE WRITE DETECTION BEFORE THE EFFECT Broker at-least-once Consumer guard at the effect Side Effect written once delivery 1 redelivery delivery cannot be deduplicated: retries, rebalances, and crashes make repeats certain the effect can: one guard, one write, in one atomic step

What the answer should contain

Claim the honest name first. Effectively-once: at-least-once delivery plus an idempotent effect. Anyone claiming exactly-once delivery is describing a closed system without failures, retries, or clocks.

Deduplicate by request, or by state. By request: a key per operation, stored with its outcome, for operations triggered from outside. By state: conditional writes (“apply only if the source offset is not yet processed”), for stream processing where the key is the position in the log.

The effect and the marker commit together. “Already done” and “done” must land in one atomic write, or a crash between them reintroduces the duplicate. In stream processing this means committing the consumer offset with the output, in the same transaction, so a replay recognizes its own work.

Fence the zombies. Every guard above assumes one active writer per key. A rebalance can make two: a consumer stalls in a long GC pause, its partition is reassigned, it wakes, and writes its result as well. The key store cannot tell which of the two is current, so each writer carries a fencing token (a generation number) and the store rejects any write from a superseded generation.

Duplicates are not the only repeat. Out-of-order arrival is the sibling problem: the guard plus a per-key sequence or version decides whether a late, older event still applies.

Test by killing processors mid-batch. Assert the effect count after recovery. If the test suite never crashes anything, it has never tested the guarantee.

Ideas worth mentioning out loud

Follow-ups to expect

Red flags in an answer

Sources