Course contentsShow
← System Design
Lesson 680 of 1,91918. Message Queues and BrokersFree lesson

Exactly-Once Delivery

Messages delivered precisely once; hardest to achieve in distributed systems, often approximated.

Exactly-Once Delivery

What you'll learn: How message systems attempt to guarantee each message is delivered and processed precisely once—and why this is so challenging.

What Is Exactly-Once Delivery?

Exactly-once delivery means a message is delivered to a consumer and processed exactly one time—no duplicates, no losses. While At-Most-Once accepts losses and At-Least-Once tolerates duplicates, exactly-once aims for the perfect middle ground.

Why It's the Hardest Guarantee

In distributed systems, achieving true exactly-once delivery is extremely difficult because of network partitions, crashes, and timing uncertainties. Consider these failure scenarios:

  • The broker sends a message, the consumer processes it, but the acknowledgment is lost—does the broker resend?
  • The consumer crashes mid-processing—did it complete the work or not?
  • The broker crashes after delivering but before recording the delivery—should it retry?

Any of these creates ambiguity about whether processing happened.

The Practical Reality

True exactly-once delivery across independent systems is theoretically impossible to guarantee in all failure scenarios. What vendors call "exactly-once" is typically:

Exactly-once semantics: The effect appears as if each message was processed once, even if internal retries occurred. This requires:

  • Idempotent operations (reprocessing produces the same result)
  • Transactional coupling between message acknowledgment and side effects
  • Deduplication using unique message IDs

For example, a payment system might process the same payment message twice internally, but idempotency ensures the account is only charged once.

When to Pursue Exactly-Once

Exactly-once semantics add significant complexity and performance overhead. Most systems use at-least-once with idempotent consumers instead—simpler and nearly as effective. Reserve exactly-once efforts for critical operations like financial transactions where duplicate processing has serious consequences.

Key Takeaway: Exactly-once delivery is the hardest guarantee in distributed messaging, often approximated through idempotency and transactional semantics rather than true prevention of duplicate delivery.