Backendcore
Idempotency keys
A client-supplied key that makes retrying a POST safe.
What it is and why it exists
The client generates a unique key per logical operation and sends it with the request. The server stores key → outcome (with a unique constraint) and, on a repeat, returns the stored outcome instead of executing again. It’s how payment APIs make retries safe, and how agent tools should handle side effects.
Quick prototype
Hope retries don’t happen.
In production, at scale
Keys required on every side-effecting endpoint and tool, stored atomically with the result, scoped per user, expired after a window, and with conflicting requests (same key, different body) rejected.
Vendors and tools
| Stripe Idempotency-Key | The canonical example |
|---|---|
| IETF Idempotency-Key header draft | Standardisation effort |
On AWS: Powertools for AWS Lambda idempotency (DynamoDB-backed); DynamoDB conditional writes.
How it fails
- Generating a new key on each retry (defeats the point)
- Storing the key after the side effect without a transaction
What the interviewer asks next
Agent called issue_refund, timed out, and retried. What prevents a double refund?
The tool call carries an idempotency key derived from the run and step (or the order ID); the refunds service sees the key already succeeded and returns the original result.