Course map

Topic 115 / Core

Delivery semantics: at-most-once, at-least-once, exactly-once and its limits with external systems

Chapter 7.3 · Event-Driven Architecture and Delivery Guarantees

What and why

When a message can be lost, delivered twice, or ideally delivered exactly once, every downstream design decision depends on knowing which guarantee actually holds — assuming the wrong one is a correctness bug, not a performance issue. At-most-once delivers zero or one time (may lose, never duplicates). At-least-once delivers one or more times (never loses, may duplicate — the practical default). Exactly-once, framed honestly, is not a free property of the broker: it is the effect of at-least-once delivery plus a deduplication/idempotency layer that makes repeated delivery indistinguishable from a single delivery — "effectively-once." Builds on: → 107 (producers and consumers — acknowledgement timing is where the semantic is decided).

Diagram

Semantic Can lose a message? Can duplicate? How it's achieved
At-most-once Yes No Ack before or without confirming processing
At-least-once No Yes Ack only after processing is durably complete; retry on any doubt
Exactly-once (effective) No No, observably At-least-once + idempotent/deduplicated processing (→ 116)

How it works

  1. The semantic is decided by when an acknowledgement happens relative to doing the work — early ack risks loss, late ack (only after processing is durably complete) risks duplicates on retry, never loss.
  2. At-most-once: send once, move on; any failure is never retried. Acceptable only where an occasional lost message is cheaper than handling duplicates.
  3. At-least-once: producers retry on any uncertain outcome, and brokers redeliver unacknowledged messages — no loss, at the cost of occasional duplicates.
  4. "Exactly-once" within a single broker boundary (coordinating a write and an offset commit atomically) can be made true inside that boundary — but the moment the effect crosses into an external system (a database write, an email send, a third-party API call), that system was never part of the transaction, and the end-to-end guarantee reduces back to at-least-once.
  5. Choose the semantic deliberately per interaction, document it, and build the consumer to match — a consumer written assuming at-most-once will corrupt state the first time it's silently redelivered under at-least-once.

Practical example

(illustrative). A notification service sends one SMS per event. Under at-most-once, a transient network blip during send means the user simply never gets that SMS — tolerable for "your package shipped," not for a one-time login code. Under at-least-once with no deduplication, the same blip triggers a retry that may succeed after the first attempt also actually succeeded, so the user gets two SMS messages — annoying, not corrupting. A dedup key (→ 116) collapses this back to exactly one visible SMS.

When to use it

  • Use at-most-once only for disposable, high-volume, low-value signals where loss is cheaper than guaranteeing delivery (best-effort telemetry).
  • Use at-least-once plus idempotency as the default for anything with business consequence — orders, payments, state transitions.
  • Never claim "exactly-once" to a team as a free property of the broker when the actual effect depends on the consumer's own idempotency work — that is the single most common delivery-semantics bug.
  • Failure scenarios: a consumer written for at-most-once assumptions (e.g. increments a counter) silently double-counts the first time at-least-once redelivers it; a team ships "exactly-once" by enabling a broker feature without checking whether a side effect that reaches an external system is actually covered by that feature's transactional boundary — it usually is not.
  • Simpler alternative: where the operation is naturally idempotent (set a field to an absolute value, rather than incrementing it), at-least-once needs no extra deduplication machinery — design the operation to not care how many times it's delivered.

Practice

(vocabulary — classification drill; 20–30 min, lab Kafka or pen-and-paper). Classify six scenarios — producer acks before writing to disk; consumer commits its offset before processing; consumer commits its offset only after processing and storing a dedup key; a fire-and-forget metrics beacon; a payment-capture call with no idempotency key, retried on timeout; a broker redelivering after a rebalance mid-processing — into at-most-once, at-least-once, or effectively-once, and state which guarantee is violated if any. Done when every classification matches the answer key, with the violation explained.

Shared lab setup

Key takeaway

At-least-once plus idempotency is the only honest way to get what people call "exactly-once" once an external system is involved. Done when you can: classify any described delivery behavior into one of the three semantics and say what breaks if the consumer assumes the wrong one. Used next in → 116 (idempotent consumers are how at-least-once becomes effectively-once), → 118 (the outbox pattern is explicitly at-least-once by design).

References

Designing Data-Intensive Applications — see references.md.

Source directory

Search the guide