0 day streak
9. Distributed systemsDelivery guarantees and idempotency

Delivery guarantees and idempotency

Delivery guarantees describe what a messaging system promises when messages or replies get lost: at-most-once means a message might never arrive, at-least-once means it will arrive but possibly more than once. The network alone can’t give you exactly-once, because a sender that hears nothing can’t tell whether its message was processed and the reply lost, or never arrived. The practical answer is to make handling idempotent, meaning doing it twice has the same effect as doing it once. For actions that aren’t naturally like that, such as charging a card, the client attaches a unique idempotency key; the server records the result under that key and, if the same key shows up again, returns the saved result instead of charging twice. Retries plus idempotency give you effectively-once.

In this lesson: A message sim with drops and retries, and a “pay twice” demo.