Idempotency for APIs
Why clients retry, how idempotency keys prevent duplicate charges and records, and how to implement them without a science project.
Networks retry. Your API will see duplicates.
A client sends POST /payments. The server commits. The response is lost. The client sends the same POST again. Without idempotency, you now have two payments.
What idempotent means
An idempotent operation can be performed more than once with the same effect as once. GET and PUT to a known URL are naturally closer to this. POST that creates a new row is not — unless you add a key.
A working approach
- Client sends
Idempotency-Key: <uuid>(see the UUID generator). - Server stores the key with the result for a retention window (for example 24 hours).
- A repeat with the same key and same body returns the original result.
- A repeat with the same key and a different body is a 409.
Related
Last verified: August 2026. Technology and pricing change — always confirm current details with the vendor.