Course contentsShow
← Cloud and Infrastructure
Lesson 552 of 2,98910. API Gateway and Event-Driven PatternsFree lesson

Message Delivery Guarantees

Exploring at-most-once, at-least-once, and exactly-once delivery semantics and their trade-offs.

Message Delivery Guarantees

You'll learn: How messaging systems handle reliability through three delivery guarantee levels and when to use each.

The Core Idea

When messages move between systems through queues or topics, networks fail, services crash, and things go wrong. Message delivery guarantees define how a messaging system promises to handle these failures. There are three primary levels:

At-Most-Once: The system delivers each message zero or one time—never duplicates, but messages may be lost. Think of it like throwing a paper airplane: you throw it once and don't check if it landed. Fast and simple, but unreliable.

At-Least-Once: The system guarantees delivery but may send duplicates if it's unsure whether the first attempt succeeded. Like a persistent friend who keeps asking "did you get my text?" until you confirm. You always get the message, but maybe twice.

Exactly-Once: The holy grail—each message delivers precisely one time, no loss, no duplicates. Like certified mail with signature confirmation. Sounds perfect, but it's complex, slow, and often impractical or impossible in distributed systems.

The Trade-offs

Each guarantee trades performance, complexity, and reliability:

  • At-most-once = fastest, simplest, least reliable (logs, metrics)
  • At-least-once = moderate speed, requires idempotency, very reliable (most common for business events)
  • Exactly-once = slowest, most complex, perfect reliability (financial transactions)

Most systems default to at-least-once because building idempotent consumers (handlers that safely process duplicates) is easier than preventing all duplicates. Your choice depends on whether occasional message loss or duplicates matter for your use case.

Key Takeaway:
At-most-once risks loss, at-least-once risks duplicates, and exactly-once is expensive—choose based on whether your application can tolerate missing or duplicate messages.