L3VLUP
Atlas

TechniqueFrameworkSoftware engineering

In a distributed system every request may arrive twice, so make the second one harmless

Arpit Bhayani · Build a Robust Payments Service Using Idempotency Keys

The idea

A client sends a payment, the network drops the reply, the client retries, and the customer is charged twice. Arpit Bhayani walks the failure and the two ways to make the repeat safe. The general technique is an idempotency key: the client attaches a unique identifier to the request, the server records the result against it, and a second arrival with the same key returns the stored result instead of acting again. The idea is wider than payments. Any operation that can be retried across a network has to be designed so that doing it twice equals doing it once, because the network guarantees that sometimes it will be.

Design every retryable operation so that doing it twice has the same effect as doing it once; the network will test this for you.

When it works

System design interviews, payment and order systems, and any API that a client might retry.

When it may fail

An idempotency key needs storage with its own consistency guarantees, and a key that expires too soon reopens the hole. The technique moves the problem to a smaller place; it does not remove it.

How to use it

In a system design answer, when you draw a write path, say what happens when the client retries. If the answer is a duplicate, add the key and the stored result, and say where the key lives.

Where it came from

Video Build a Robust Payments Service Using Idempotency Keys · Arpit Bhayani

What the source says. Arpit Bhayani shows why a payment can repeat when a reply is lost, and the two ways to make the repeat safe, including idempotency keys stored with their results.

Open the source at 4:06 to 11:13 (opens in a new tab)Checked against the clip · reviewed 2026-10-16

Connected ideas

Concepts

Put it to work on L3VLUP

More like this