POST /appointments, the booking is made, but the response never reaches you, a blind retry books the patient twice and sends two confirmations.
Send an Idempotency-Key header on every POST, PUT, PATCH and DELETE:
- Use a new unique value (a UUID is ideal) for each operation, and the same value when you retry that operation.
- The first response is saved for 24 hours. A retry with the same key returns it again, with the header
Idempotent-Replayed: true, and nothing runs twice. - The same key with a different body or path returns
422 idempotency_key_reused. - A retry while the first request is still running returns
409 idempotency_in_progress. Wait a moment and retry. - Server errors (5xx) are not saved, so a retry runs again.
- The header is optional. Without it, a request works as usual but has no retry protection.