Idempotency
What idempotency means precisely, idempotency keys, and the financial-systems pattern.
Overview
Why idempotency matters
An idempotent operation can be performed multiple times with the same result: f(x) = f(f(x)). It is critical for retries, because retrying a non-idempotent operation causes duplicate side effects.
The canonical case is a payment API. A network timeout triggers a client retry; the first request succeeded but its response was lost, so the retry creates a second charge. With an idempotency key, the server detects the duplicate and returns the original response. Here is that exchange, step by step.
- The client sends POST /payments with the header Idempotency-Key: abc-123.
- The server processes the payment and stores the key with its result in a dedup table, with a time to live (TTL) of 24h.
- The response is lost on the way back, so the client never sees it.
- The client retries with the same key.
- The server looks up abc-123 in the dedup table and finds it.
- The server returns the original response. There is no double charge.
> [!IMPORTANT] The industry standard is Stripe-style keys: a UUID per logical operation, sent as Idempotency-Key, stored with the response for 24 hours.
Key concepts
- Idempotent
- Idempotency key
- Dedup table
- Concurrency on same key
- Stripe / AWS API pattern
- Saga pattern
Interview questions
- Walk me through implementing idempotent payment processing.
- How do you handle idempotency for long-running operations?
- When can you skip idempotency keys?
Sign up free to read the full topic
More SRE topics
Start free on Cariara · Coding problems · System design studio