How small failures become outages
The recommendations service slows down. Orders calls it with no timeout, so each request holds a thread for 8 seconds. Orders runs out of threads and stops answering, even for checkouts that never needed recommendations. Users and the gateway retry, tripling the load. A non-critical feature has taken down checkout.
Every pattern in this chapter breaks one link in that chain.
Timeouts: the first line of defence
- Every network call needs a timeout. Library defaults are often "infinite" or 30+ seconds.
- Derive timeouts from a latency budget. If the user-facing SLO is 800 ms and the request calls three services in sequence, they can't each have a 1-second timeout.
- Set per-call timeouts slightly above the dependency's p99, not its average.
- Propagate deadlines: pass the remaining budget downstream (gRPC deadlines do this) so deep services stop working on requests the user has already abandoned.
Retries: helpful medicine, dangerous dose
Retry only transient errors (timeouts, 503, connection resets), never validation errors (400) or "not allowed" (403). And only retry idempotent operations, or ones protected by idempotency keys.
Exponential backoff with jitter: wait random(0, base × 2^attempt), capped. The randomness stops thousands of clients retrying in synchronised waves.
Retrying at every layer. Three layers each retrying three times turns one failing request into 64 calls on the deepest service, exactly when it's weakest. Retry at one layer (usually closest to the caller), and use a retry budget (e.g. retries ≤ 10% of requests).
Circuit breakers
A circuit breaker wraps calls to a dependency and tracks failures:
Failing fast frees threads immediately and gives the struggling dependency room to recover. Pair it with a fallback: cached data, a default ("popular items" instead of personalised recommendations), or a degraded feature.