We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
6 system design questions lean on this idea. Each walks through the full answer.
System Design Masterclass · Core Fundamentals
Free preview: the first 2 parts of this 9-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Core Fundamentals
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
You're buying a flight ticket. $847. You click the "Pay Now" button. The page freezes. Nothing happens for 5 seconds. You're not sure if it went through. So you click again.
Here's the million-dollar question (sometimes literally): did you just buy one ticket or two?
If the payment system isn't designed carefully, you just got charged $1,694. Two flights. Same seat. Double the charge. And now you're on the phone with customer support for 45 minutes trying to get a refund.
This isn't a hypothetical. Double-charges are a routine class of incident, and the reason is structural rather than careless: the retry that causes them is usually correct behaviour. Your browser retries. Your mobile network retries. Your payment provider's webhooks are delivered at least once by design, which means more than once is normal and expected. Every layer between the button and the ledger is built to try again, so the ledger is the layer that has to refuse to count it twice.
Idempotency is the property that prevents this. An idempotent operation produces the same result whether you execute it once or a hundred times. Click "Pay" once, click it ten times, you get charged exactly once. That's idempotency.
It sounds simple. It's deceptively hard to implement. And it's absolutely critical in any system that handles money, state changes, or anything you can't easily undo.
An operation is idempotent if performing it multiple times produces the same outcome as performing it once.
Let's ground this with everyday examples before we get technical.
Idempotent:
Not idempotent:
The specification defines which methods are idempotent:
| Method | Idempotent? | Why |
|---|---|---|
| GET | Yes | Reading data doesn't change anything. Fetch a user profile 100 times, same profile every time. |
| PUT | Yes | "Set this resource to this value." PUT /users/42 {name: "Roni"}, do it once or ten times, the name is "Roni". |
| DELETE | Yes | "Delete this resource." Delete user 42 once, they're gone. Delete user 42 again, they're still gone (you might get a 404, but the state didn't change). |
| HEAD | Yes | Same as GET but returns only headers. Read-only. |
| POST | No | "Create a new thing." POST /orders creates an order. Do it twice, you get two orders. |
| PATCH |
The key insight: GET, PUT, DELETE are naturally idempotent. POST is not. And POST is what you use for the most dangerous operations, creating orders, processing payments, sending messages.
It is easy and good
“It is really nice and good Please join the course”
| Depends |
PATCH {name: "Roni"} is idempotent. PATCH {balance: +100} is not (adds $100 each time). |