Course contentsShow
← Computer Science
Lesson 2710 of 2,87260. Distributed Data and CommunicationFree lesson

At-Most-Once, At-Least-Once, Exactly-Once Delivery

Understanding delivery semantics, acknowledgments, and the tradeoffs between duplicate messages and message loss.

At-Most-Once, At-Least-Once, Exactly-Once Delivery

What you'll learn: You'll understand the three fundamental delivery guarantees in distributed messaging and why "exactly-once" is surprisingly complex to achieve.

The Three Delivery Semantics

When messages travel across networks between systems, things can go wrong—networks partition, processes crash, acknowledgments get lost. Distributed systems offer three delivery guarantees, each with different tradeoffs:

At-Most-Once Delivery

The sender transmits a message but never retries. If the message is lost or the receiver crashes, too bad—it won't arrive. This guarantees no duplicates but allows message loss.

Analogy: Sending a postcard and never checking if it arrived. You won't send duplicates, but it might get lost in the mail.

At-Least-Once Delivery

The sender retries until receiving an acknowledgment from the receiver. This prevents message loss but can cause duplicates if the acknowledgment itself is lost (the sender retries even though the first delivery succeeded).

Analogy: Calling someone repeatedly until they answer. If they picked up but you didn't hear their "hello," you'll call again—they'll hear the phone ring twice.

Exactly-Once Delivery

Messages arrive exactly one time—no loss, no duplicates. This sounds ideal but is extremely difficult to implement. It typically requires:

  • Idempotent processing (handling duplicates gracefully)
  • Deduplication identifiers (tracking message IDs)
  • Transactional coordination between delivery and processing

Many systems claiming "exactly-once" actually mean "effectively-once" through idempotency—duplicates may arrive, but processing them multiple times has the same effect as processing once.

The Fundamental Tradeoff

You cannot have both zero message loss and zero duplicates without adding complexity (deduplication logic, stronger consistency guarantees, or transactional semantics). Most real systems choose at-least-once with idempotent handlers.

Key Takeaway: At-most-once allows loss but no duplicates; at-least-once allows duplicates but no loss; exactly-once eliminates both but requires careful coordination—choose based on whether duplicate processing or message loss is more harmful to your application.