Idempotency
What is it?
An operation is idempotent if doing it multiple times has the same effect as doing it once.
Explain like I'm 5
Why was it created?
Networks retry requests, and duplicates happen. Idempotency was emphasized so repeated operations don't cause double charges or duplicate records.
Where is it used?
- Payment processing
- Retried API requests
- Message processing
- Webhooks and queues
Why should developers care?
It's essential for reliable APIs and payments, and a frequent topic in backend design and interviews.
How does it work?
You design an operation so repeats are safe — for example, by using a unique key so the server recognizes a duplicate request and returns the original result instead of doing the work again.
Real-world example
A payment API accepts an idempotency key; if the client retries after a timeout, the server sees the same key and avoids charging the card twice.
Common use cases
- Safe retries
- Exactly-once effects despite duplicates
- Reliable payments
- Processing queued messages
Advantages
- Safe to retry
- Prevents duplicate side effects
- More resilient systems
- Simplifies failure handling
Disadvantages
- Requires deliberate design
- Tracking keys adds state
- Not every operation is naturally idempotent
When should you use it?
Whenever an operation might be retried and duplicates would cause harm.
When should you avoid it?
It's not something to avoid; rather, decide where it's needed (mainly state-changing operations).
Alternatives
Related terms
Interview questions
Beginner
- What does idempotent mean?
- Which HTTP methods are typically idempotent?
Intermediate
- What is an idempotency key?
- Why do payments need idempotency?
Senior
- How would you design an idempotent payment endpoint?
- How do you handle idempotency across retries and concurrency?
Common misconceptions
- "GET, PUT, DELETE are idempotent so all REST is safe to retry" — POST usually isn't, which is why payments need idempotency keys.
- "Idempotent means it does nothing on repeat" — it means the end effect is the same, not that nothing runs.
Fun facts
- GET, PUT, and DELETE are designed to be idempotent in HTTP; POST generally is not.
- Idempotency keys are how payment APIs make retries safe.
Timeline
- 2010s — Idempotency keys become standard in payment and API design
Learning resources
Quick summary
Idempotency means repeating an operation has the same effect as doing it once, making retries safe and preventing duplicate side effects.
Cheat sheet
- Repeat = same effect as once
- Makes retries safe
- Use idempotency keys
- Critical for payments