How to make API retries safe
An integration caller can time out after a write succeeds. Design the API so the caller can try again and recover the result without creating a second record.
One operation, three responses
This sample API contract accepts a reviewed sales intake. A caller sends an idempotency key so a repeated request can reuse the first result.
POST /v1/reviewed-intake
Idempotency-Key: demo-quote-01
{ "quantity": 25, "due": "Friday", "matches": 1 }
- POST /v1/reviewed-intake
201· Task created{"taskId":"demo-task-01","quantity":25,"due":"Friday"}- Repeat the same request
200· Original result reused{"taskId":"demo-task-01","quantity":25,"due":"Friday"}- Reuse the key with quantity 26
409· Changed request rejected{"error":"IDEMPOTENCY_KEY_CONFLICT"}
The fixture records one task across the three requests. In a deployed integration, persist request keys with the associated operation, define their retention, and document the response for retry and conflict cases.
What to agree before implementation
- Which operations can repeat
- List the writes that users, jobs and webhooks might repeat. Identify the caller and define what counts as the same operation.
- What the caller can expect
- Agree how a repeat gets the original outcome, how a changed request is rejected, how long keys are retained, and how an in-flight request is reported.
- How acceptance works
- Run an identical repeat, a changed body with the same key, overlapping deliveries and a retry after an uncertain response. Confirm the stored outcome and the number of writes.
For an example that includes a human reviewer, see the Inbox-to-CRM worked example.