Detailed Explanation
According to RFC 9110, HTTP methods GET, HEAD, PUT, DELETE, and OPTIONS are inherently idempotent. Executing GET /users/100 five times returns the same data without altering server state. In contrast, POST is non-idempotent. To make POST operations idempotent (e.g. payment processing or order creation), APIs use an Idempotency-Key HTTP request header stored in a fast key-value database like Redis with a 24-hour TTL.
Code Example
POST /v1/payments HTTP/1.1
Host: api.example.com
Authorization: Bearer jwt_token_xyz
Idempotency-Key: 7b928374-4b10-482a-912f-981249120491
Content-Type: application/json
{
"amount": 5000,
"currency": "USD"
}Idempotent POST request using an Idempotency-Key header
Common Mistakes to Avoid
- Designing PUT endpoints that mutate state non-deterministically (e.g., incrementing counter values)
- Assuming POST requests are idempotent without implementing an Idempotency-Key header
- Returning 500 Internal Server Errors when a duplicate idempotent request is received instead of replaying the original 200/201 cached response payload
