Idempotency & Reliability
What idempotency means in APIs
- Repeating the same request does not change the outcome beyond the first successful application.
- Safe methods (GET, HEAD, OPTIONS) should be idempotent; PUT/DELETE often are when designed well.
- POST payments and creates are the usual non-idempotent hot spots.
Why it matters in retries
- Networks, gateways, and clients retry on timeouts and ambiguous errors.
- Without idempotency, retries create duplicate charges, orders, or side effects.
- Define which status codes are retryable (502, 503, 429) vs terminal (400, 404).
Idempotency keys
- Client sends a unique key (header) per logical operation; server stores outcome mapping for a TTL window.
- On duplicate key with same payload, return the same response as the first success.
- On duplicate key with different payload, return 409 or a documented conflict.
Safe retries in distributed systems
- Combine idempotency keys with exactly-once-ish semantics via dedupe stores or natural keys.
- Use outbox/inbox patterns for reliable messaging alongside HTTP callbacks.
- Document at-least-once delivery for webhooks and how signatures + idempotency interact.