Reliability Patterns
Stop failures from cascading with timeouts, circuit breakers, bulkheads, load shedding, backpressure and graceful degradation.
Intermediate · about 3 hours · difficulty 3/5
Learn first: Idempotency, Retries and Timeouts, Service Communication and Discovery
In a large system something is always failing. Reliability patterns make sure one failure stays small.
Core patterns
- Timeouts on every remote call (see the idempotency topic).
- Circuit breaker: after repeated failures to a dependency, "open" the circuit and fail fast for a cool-down period, then let a few trial requests through (half-open). Prevents threads piling up on a dead service and gives it room to recover.
- Bulkheads: isolate resources (separate thread pools or connection pools per dependency) so a slow recommendation service cannot exhaust the threads that serve checkout.
- Retries with backoff and jitter, within a budget.
- Load shedding: when overloaded, reject low-priority work early (return 503) so high-priority requests still succeed. Better to serve 80 percent well than 100 percent badly.
- Backpressure: slow producers down when consumers fall behind, instead of buffering forever.
- Graceful degradation / fallbacks: if personalised recommendations fail, show bestsellers; if ratings are down, hide the stars. Keep the core flow (browse, pay) alive.
Preventing cascading failure
Cascades usually start with one slow dependency, then exhausted threads, then retries amplifying load, then healthy services falling over. Combine timeouts, breakers, bulkheads and shedding to break each link. Also avoid synchronized behaviour: thundering herds after a cache flush, or every client retrying at the same second.
Testing resilience
Chaos engineering deliberately injects failures (kill instances, add latency) in controlled experiments to verify these defences actually work. Start in staging with simple fault injection before anything like Chaos Monkey.
Pitfalls
- Circuit breakers with thresholds nobody tuned, tripping on normal noise or never tripping.
- Fallbacks that call another fragile dependency.
- Unbounded in-memory queues that turn overload into out-of-memory crashes.
You are ready to move on when you can trace how a slow payment gateway could take down an entire checkout service and name the pattern that breaks each step of that cascade.
Key concepts
- Circuit breaker
- Bulkheads
- Load shedding
- Backpressure
- Graceful degradation and fallbacks
- Cascading failures
- Chaos engineering
Mini project
Wrap calls to a deliberately flaky service with a circuit breaker and a bulkhead (Resilience4j, Polly, opossum or your own). Load test with and without them while the dependency slows to 5 s, and compare the caller's latency and error rate.
Check yourself
What problem does a circuit breaker solve that a timeout alone does not?
Free resources
- CircuitBreaker (Martin Fowler)
- Addressing cascading failures (Google SRE)
- Cloud design patterns (Microsoft)
- Principles of Chaos Engineering (principlesofchaos.org)