What is Idempotency?
Idempotency, told as a story about a ticket booth that only honors a numbered ticket once.
The payment stalls, so the guest taps the button twice.Just a worried extra tap — but the money leaves twice.
A repeated request looks brand-new, so it gets processed again.Without a number, there's no way to tell them apart.
The same ticket number shows up again — count it just once.Thanks to the number, sending it twice still means one result.
This is the difference a number makes.With a number it's safe; without one, it just happens twice.
Storing those numbers costs resources too.You can't keep them forever, so they expire — and this always pairs with retrying.
Idempotency = making sure the same request (same ticket number) arriving twice still produces the result only once.
A property where sending the same request multiple times produces the same result as sending it once. An idempotent key identifies each request, and already-seen keys are stored to filter out duplicates — especially important when a dropped connection triggers a retry.
When grown-ups say it
- Idempotency
- The property that sending twice gives the same result. Same as sending it just once.
- Idempotent key
- The unique number written on the ticket. This number is how you tell requests apart.
- Deduplication
- Filtering out a ticket with a number you've already seen. The second and later copies aren't processed.
- Retry
- Sending the request again after it's dropped. Retrying is only safe when the request is idempotent.
- Duplicate payment prevention
- The most common place idempotency shows up. The same payment number means money is taken only once.
- At-least-once / Exactly-once
- Names for how a message gets delivered. Just knowing the names is enough — a message may arrive more than once, or exactly once.
- Naturally idempotent operations
- An operation that gives the same result no matter how many times you do it. Like 'set the max to 10' — do it twice and it's still 10.
- Ticket / Request ID
- The unique number attached to each request. It plays the same role as the idempotent key.