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

At-Least-Once Delivery

Messages guaranteed to be delivered but may arrive multiple times; requires idempotent consumers.

At-Least-Once Delivery

What you'll learn: How message brokers guarantee delivery by potentially sending messages multiple times, and why your consumers must handle duplicates.

The Core Guarantee

At-least-once delivery means the message broker guarantees every message will reach the consumer, but might deliver the same message more than once. This happens when the broker isn't certain whether delivery succeeded—for example, if a consumer acknowledges receipt but the acknowledgment gets lost in the network.

The broker plays it safe: "I'm not 100% sure you got it, so I'll send it again."

Why Duplicates Happen

Consider this sequence:

  1. Broker sends message to consumer
  2. Consumer processes it successfully
  3. Consumer sends acknowledgment back
  4. Network hiccup—acknowledgment never reaches broker
  5. Broker assumes failure, resends the message
  6. Consumer receives the same message again

The broker chose availability over exactness. Rather than risk losing a message, it risks sending duplicates.

The Idempotency Requirement

Since duplicates are inevitable, your consumer must be idempotent—processing the same message multiple times should have the same effect as processing it once.

Bad (not idempotent): balance = balance + 100 (running twice adds $200!)

Good (idempotent): if transaction_id not in processed_set: balance += 100; mark transaction_id as processed

Real-World Analogy

Think of a worried parent texting "Did you get home safe?" If you reply but they don't see it (bad signal), they'll text again. You receive the question twice—but answering "yes" multiple times doesn't change reality. Your response is naturally idempotent.

Compared to At-Most-Once

With at-most-once delivery (lesson 678), you risked losing messages. With at-least-once, you risk duplicate messages but never lose them. Most systems prefer duplicates over data loss.

Key Takeaway: At-least-once delivery guarantees no message loss but requires idempotent consumers to handle inevitable duplicates safely.