Skip to content
System Designer

Stay correct · 3 minutes

Exactly once, on purpose

Retries are normal, so every action must be safe to repeat.

Open this lesson
Retries are normal, so every action must be safe to repeat.

Did my payment go through?

Networks drop answers. A phone taps Pay, the payment succeeds, the reply is lost, and the app tries again. Without care the customer is charged twice. A retry is safe only if repeating the action has the same effect as doing it once. That property is called idempotency.

The key

The purchase keeps one key across retries. An atomic ledger returns its stored receipt instead of repeating the charge.

Try the idea

The queue delivers some payments twice, and customers are charged twice. Add an idempotency store.

Key numbers

Duplicate rate in a queue
≈ 0.1 to 1 percent. at-least-once delivery, approx.
Key lookup
≈ 1 ms. approx.
Keep keys for
≈ 24 hours. approx.

Check your reasoning

Think through these questions before opening the lesson. In the game you can test the idea and compare your reasoning.

  • What is an idempotent action?
  • Why do duplicates happen with queues?
  • Where does the idempotency key come from?

The key point

Give every action a key, and repeating it becomes harmless.

Practise this idea

Continue through the lesson tracks