Idempotency, Retries & Timeouts
- Networks fail mid-request → clients retry → servers must make operations idempotent.
- Idempotency key: client sends a unique key (
Idempotency-Key: <uuid>); server stores key → result and returns the saved result on repeats. Essential for payments. - Retries: exponential back-off + jitter, cap the number, and only retry idempotent/safe operations.
- Timeouts everywhere; circuit breakers stop hammering a failing dependency; bulkheads isolate resources.
- Distributed transactions: avoid 2PC across services; use sagas (sequence of local transactions with compensating actions) and the outbox pattern (write the event to an outbox table in the same DB transaction, relay it to the queue).