- Published on
What is Idempotency and why it matters?
- Authors
- Name
- Pankaj Tanwar
- @the2ndfloorguy
Imagine you are ordering a pizza. You tap on "Place Order", nothing happens. You tap again, same. You panic and tap it again. Now, you are either getting a pizza, or may be 3 pizzas and a very confused delivery guy.
This is exactly the problem Idempotency solves in distributed systems.
What is Idempotency?
In simple terms, Idempotency means that performing same operation multiple times produces the same result, as performing it once.
It's like pressing "Confirm" button that only works first time, and ignores duplicates.
In distributed systems, network failures, timeouts and retires and inevitable. Without idempotency, these things can create blunders likes -
- Duplicate payments
- Multiple account creations
- Inconsistent data states
Something like POST /make-payment
endpoint. Unless you design it carefully, every call could trigger a new payment.
Why it matters?
A very very common example is ATM withdrawal. Suppose, you are withdrawing 1000 INR and suddenly network fails after you hit "Confirm".
ATM might retry the transaction. Without idempotency, it can withdraw 2000 INR from your account. But with idempotency, no matter how many times its retried exactly 1000 INR is withdrwan. ATM achieves this by generating & attaching a unique transaction id. If same id comes, system just returns back original result instead of creating a new transaction.
Always assume systems fail. Networks flake. Users double-tap. Your client might retry. Even your backend might retry. If your system is not idempotent, you might get into trouble.
Idempotency helps your system become safe and predictable in distributed environments.
Imagine you are ordering a pizza. You tap on "Place Order", nothing happens. You tap again, same. You panic and tap it again. Now, you are either getting a pizza, or may be 3 pizzas and a very confused delivery guy.
This is exactly the problem Idempotency solves in distributed systems.
What is Idempotency?
In simple terms, Idempotency means that performing same operation multiple times produces the same result, as performing it once.
It's like pressing "Confirm" button that only works first time, and ignores duplicates.
In distributed systems, network failures, timeouts and retires and inevitable. Without idempotency, these things can create blunders likes -
- Duplicate payments
- Multiple account creations
- Inconsistent data states
Something like POST /make-payment
endpoint. Unless you design it carefully, every call could trigger a new payment.
Why it matters?
A very very common example is ATM withdrawal. Suppose, you are withdrawing 1000 INR and suddenly network fails after you hit "Confirm".
ATM might retry the transaction. Without idempotency, it can withdraw 2000 INR from your account. But with idempotency, no matter how many times its retried exactly 1000 INR is withdrwan. ATM achieves this by generating & attaching a unique transaction id. If same id comes, system just returns back original result instead of creating a new transaction.
Always assume systems fail. Networks flake. Users double-tap. Your client might retry. Even your backend might retry. If your system is not idempotent, you might get into trouble.
Idempotency helps your system become safe and predictable in distributed environments.