CSE Roadmap

Core tier · about 4 hours · 7 parts

Part 2 of 7 · 2 min read

Three promises

A system can promise to deliver a message never more than once, never less than once, or exactly once.

Think of sending a letter. You can drop it in a postbox and hope (cheap, but it might be lost). You can send it by a service that keeps resending until the receiver signs (it arrives, but the receiver may get two copies if a signature slip went missing). Or you can ask for something that neither loses nor doubles a letter. The third sounds best, and it turns out to be the one that cannot be bought directly.

The books name three delivery guarantees. The UDS book lists "at-most-once or at-least-once" among the trade-offs that a broker must pick.

At most once

At most once delivery means each message is delivered zero or one times. It is never repeated, but it can be lost.

Example: a metrics agent sends a reading by UDP with no retry. If the packet is dropped, that reading is gone, and nobody tries again.

At least once

At least once delivery means each message is delivered one or more times. It is never lost, but it can be repeated.

Example: a queue keeps resending a message until a consumer acknowledges it. If the ack is lost, the consumer sees the message twice.

Exactly once

Exactly once means each message has its effect one time, no more and no less.

Example: a customer is charged 20 dollars for an order exactly one time, even though the payment message was delivered twice.

The table summarises what each promise does when a message goes wrong:

Promise Message lost? Message repeated? Extra work for the system
At most once Possible Never None. Fastest and simplest
At least once Never Possible Retries and acknowledgments
Exactly once Never Never (in effect) Retries plus de-duplication

DDIA explains when losing a message is acceptable. Periodic sensor readings and metrics can lose an occasional point, because the next value arrives soon. The book also warns that if many messages are dropped, it may not be obvious that the metrics are wrong. For counters, every lost message makes the total incorrect, so reliable delivery matters more. The same book notes that if loss is acceptable, you can get higher throughput and lower latency on the same hardware.

Read it as

At most once means "send and forget". At least once means "send until confirmed". Exactly once is not a delivery method but a goal that is reached by combining the second with careful receivers.

Check yourself:

  • Which guarantee fits a stream of temperature readings sent every second, and why?
  • Which two guarantees both avoid duplicates, and which one avoids loss?