Practice this topic in a realistic system design interview
Over an unreliable network, a sender cannot always know whether a message was processed. So every messaging system has to choose how it behaves when that uncertainty appears.
In this chapter, we'll look at what at-most-once, at-least-once, and exactly-once really mean, and how real systems avoid losing or duplicating messages.
Suppose an order service sends a message to a payment service saying, "charge this customer $50." The order service waits for a response, but nothing comes back.
What happened? There are three possibilities:
From the sender's side, these three cases look identical. All it sees is silence.
Now the sender has to make a decision. If it does not retry, the payment may never happen. If it does retry, the customer may be charged twice.
This is the core problem behind delivery semantics.
There are three common delivery guarantees:
| Guarantee | Retry? | When the consumer acknowledges | Main Risk |
|---|---|---|---|
| At-most-once | No | Before processing | Message loss |
| At-least-once | Yes, until acknowledged | After processing | Duplicates |
| Exactly-once | Yes | After processing, plus deduplication | More complexity |
Each guarantee comes from a specific choice about when to retry and when to acknowledge. Let's look at each one in detail.