API Design interview question · Most asked
How do idempotency keys work for POST requests?
Summary
The client sends a unique Idempotency-Key header per logical operation; the server stores the key with a hash of the request and the resulting response, and if the same key arrives again it returns the stored response instead of performing the operation twice.
Longer Answer
Handle concurrent duplicates (lock or 'in progress' state returning 409), reject reuse of a key with a different payload, scope keys per client, and expire them after a retention window (e.g., 24h). Essential for payments and order creation.
Key Points
- Client-generated key per operation
- Store request hash + response
- Handle in-flight duplicates
- Expire keys
More most-asked API Design questions
- What makes an API RESTful, and what are good REST design practices?
- Which HTTP methods are safe and idempotent, and why does it matter?
- Which HTTP status codes should an API use, and when?
- Compare offset pagination and cursor (keyset) pagination.
- How should you version an API?
- When would you choose GraphQL over REST, or gRPC over both?