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.
Connected ideas
Says something similar
Consensus is agreeing on one value when any machine may crash and the network may lieAsk what a consensus protocol assumes about crashes and the network; its guarantee is only as strong as those assumptions.
Concepts
Put it to work on L3VLUP
More like this
- TechniqueSoftware engineeringVideo located
An index turns a table scan into a handful of page reads, paid for in write speed and disk
An index buys read speed with write speed and disk; add one for the query you run most and remove the ones you never use.
From B-tree vs B+ tree in Database Systems · Hussein Nasser
- FrameworkSoftware engineeringBook
Complexity is what you must hold in your head to make a safe change
Judge a design by how much a reader must understand to change it safely, and prefer deep modules behind small interfaces.
From A Philosophy of Software Design · John Ousterhout
- ArgumentSoftware engineeringBook
Speed and stability rise together. The trade-off is the myth
The practices that make shipping frequent are the ones that make it safe, so do not trade one for the other.
From Accelerate · Nicole Forsgren, Jez Humble and Gene Kim
- FrameworkArtificial intelligenceVideo located
The context window is not the constraint people think it is; attention across it is
A long window degrades before it fills; curate and order what goes in rather than relying on size.
From Why LLMs Get Dumb (Context Windows Explained) · NetworkChuck