9. Idempotency
One-liner. At-least-once delivery is the default; make the effect happen once.
Memorize
- Idempotency key supplied by the client, stored with the result → replay returns the same response.
- Upsert instead of insert; conditional writes (
if version = n). - Dedupe window: store keys with TTL ≥ the retry window.
- Exactly-once end-to-end does not exist across arbitrary systems — it's at-least-once + idempotent effects.
- Payment APIs: same key + same body = one charge; same key + different body = 409.
Trap. Retrying a POST that creates a resource without a key — duplicates on every timeout. Do this. Ask what happens if the same message is delivered twice, in the same second.
Check
A payment request times out at the client but succeeded server-side. The client retries. What prevents a double charge?
Why
The server dedupes by key and returns the original result; timeouts only change how often retries happen.