Containing Failure in Distributed Systems
Question: when a dependency is slow or failing, how do you stop the failure from spreading to its callers and the rest of the system?
Reliability and availability covers redundancy and failover: keeping enough healthy capacity. This hub covers how a caller behaves when a call goes wrong.
Forces
- Availability: in a synchronous chain, the request succeeds only if every service on the path does.
- Latency: a slow dependency is often worse than a failed one. Waiting callers hold threads and connections until they run out, and the slowdown moves upstream.
- Correctness: repeating a call can repeat its side effect.
- Capacity: retries add load to a dependency that is already struggling, and many clients retrying together can keep it down.
Options
Choose these together. A retry inside a timeout inside a circuit breaker behaves differently from the same pieces arranged another way. Retries at several layers multiply.
Testing the controls
A failure control that has never fired is a guess. Fault injection makes it fire on purpose.
- At the network layer: a service mesh can add a delay to, or return an error for, a chosen share of calls to one service, without code changes. Istio, for example, configures this per route. It tests whether timeouts, retries, circuit breakers, and fallbacks behave as designed.
- As an experiment: chaos engineering frames each test as a hypothesis about steady state, such as “checkout success stays above 99 percent if the recommendation service adds two seconds of latency”. Start with a small blast radius, such as one header-selected test user or 1 percent of traffic, have a way to stop at once, and widen only when the hypothesis holds.
- Limits: network-level injection simulates slow and failing calls, not corrupted data, a full disk, or clock skew. Those need other tools or game days.
A fallback is the control most worth testing this way, because it rarely runs otherwise.
Leads to
- Retries and redelivery lead to idempotency.
- A degraded mode needs a definition of what the client observes. Record it with the NFRs for the affected operation.
- Asynchronous messaging removes some synchronous dependencies altogether, at the cost of eventual consistency.
- A service mesh can apply timeouts, retries, and circuit breaking outside application code.
- Detecting these failures needs metrics, tracing, and health checks.
Seen in cases
- URL shortener: a degradation plan. When the database is overloaded, serve cached redirects, cache 404/410 responses briefly, and trip circuit breakers to protect latency.
- Public chat room: an unresolved question about bursts that exceed a fixed buffer, which is a load-shedding or back-pressure decision.
- The extended framework collection lists missing discussion of retries, circuit breakers, and database failover among the most influential interview errors.
- AI and RAG: the tool runtime in the boundary map retries within bounds and normalizes errors, and the enforcement step validates invariants and then falls back or repairs. The deterministic agent template caps recursion with a specific exception.
Gaps
- Choosing timeout values from latency percentiles.
- Retry budgets and how retries at different layers interact.
- Cell-based architecture as a way to limit the scope of a failure.
- Separating robustness against anticipated disturbances from resilience to surprise (Woods).
Sources
- Circuit breaker – microservices.io. In the pattern language, this is the only pattern in the reliability group; the others come from Nygard and Newman.
- CircuitBreaker – Martin Fowler.
- AWS Builders’ Library: timeouts, retries, and backoff with jitter, load shedding, avoiding fallback.
- Nygard 2018: part I, stability antipatterns and stability patterns; chapter 17, chaos engineering. Newman 2021: chapter 12 (resiliency). Richardson 2019: chapter 3 (circuit breaker).
- Fault injection – Istio.
- Principles of chaos engineering.
Library sources
- Nygard 2018, Release It! Design and Deploy Production-Ready Software, Second Edition – part I; chapter 17 on Testing the controls
- Newman 2021, Building Microservices: Designing Fine-Grained Systems, Second Edition – chapter 12
Further reading:
- Woods 2015, Four Concepts for Resilience and the Implications for the Future of Resilience Engineering (doi:10.1016/j.ress.2015.03.018)
- AWS 2024, Reducing the Scope of Impact with Cell-Based Architecture
- Richardson 2019, Microservices Patterns: With Examples in Java – chapter 3