Volume 4 · Chapter 9 — .NET Distributed Systems and Microservices Architecture
Resilience and Fault Handling
9.1 Introduction
In distributed systems, failure is constant, not exceptional - networks drop, services become unavailable, dependencies slow down, and infrastructure hiccups. Resilience engineering designs systems that keep operating or recover quickly when this happens. The composable patterns - timeout, retry, circuit breaker, bulkhead, fallback - combine into a defense that turns a dependency’s bad day into a contained, recoverable event. In .NET these are expressed with the Polly-based resilience pipelines. (Volume 7 covers this in depth.)
9.2 Timeouts - the Foundation
The most important resilience pattern is the simplest: never wait forever. A call without a timeout can hold a request thread and resources indefinitely when a dependency hangs, which is how one slow dependency cascades into a full outage. Every remote call needs a bounded timeout that fails fast and returns a meaningful error.
9.3 Retry, Circuit Breaker, and Bulkhead
Retries recover from transient faults - but only transient ones, capped, with exponential backoff and jitter, or they become a retry storm that amplifies load. A circuit breaker tracks the failure rate and, once it crosses a threshold, opens to fail fast without calling a dead dependency, then half-opens to test recovery. A bulkhead isolates resources per dependency so one failure can’t exhaust everything.
stateDiagram-v2 [*] --> Closed Closed --> Open: failure rate > threshold Open --> HalfOpen: cool-down elapsed HalfOpen --> Closed: trial call succeeds HalfOpen --> Open: trial call fails
// Compose timeout + retry + circuit breaker for outbound calls (Polly-based).
builder.Services.AddHttpClient<FraudClient>()
.AddResilienceHandler("fraud", b =>
{
b.AddTimeout(TimeSpan.FromSeconds(2));
b.AddRetry(new() { MaxRetryAttempts = 3, BackoffType = DelayBackoffType.Exponential, UseJitter = true });
b.AddCircuitBreaker(new() { FailureRatio = 0.5, MinimumThroughput = 20 });
});
9.4 Fallback, Health Checks, and Fault Injection
A fallback provides a degraded-but-useful response (a cached value, a default) when a call ultimately fails, enabling graceful degradation. Health checks (liveness, readiness, dependency) give orchestrators and load balancers the signals to route and restart correctly. And resilience that is never exercised tends to be misconfigured, so fault-injection/chaos testing deliberately fails dependencies to prove the patterns actually engage before a real incident.
Why are retries alone not enough - and how can they make things worse?
Retries alone are insufficient, and used carelessly they actively worsen failures. Retries only address transient faults - a momentarily dropped connection, a brief blip - by trying again; but against a dependency that is genuinely overloaded or down, retrying doesn’t help and instead amplifies the problem. If every caller retries immediately and in lockstep, the retries multiply the load on the struggling dependency precisely when it’s weakest, creating a “retry storm” that prevents it from recovering and can turn a partial degradation into a full outage - effectively a self-inflicted denial-of-service. Retries also risk duplicate side effects if the operation isn’t idempotent (retrying a payment could charge twice). So retries must be used carefully and combined with other patterns. First, retry only transient, retryable failures (not business errors or clearly-permanent failures), cap the number of attempts, and use exponential backoff with jitter so retries are spread out over time rather than hammering in synchronized waves - this prevents the retry storm. Second, pair retries with a circuit breaker: once failures are sustained (not transient), the breaker opens and stops the retries entirely, failing fast so the caller doesn’t pile up requests on a dead dependency and gives it room to recover - the breaker is what distinguishes “transient, worth retrying” from “it’s down, stop hammering it.” Third, bound each attempt with a timeout so a slow dependency can’t hold resources. Fourth, ensure operations are idempotent so retries (and at-least-once delivery) don’t cause duplicate effects. And add bulkheads to isolate the impact. So retries are one pattern in a resilience stack, not a standalone cure: without backoff, jitter, caps, circuit breakers, timeouts, and idempotency, retries can amplify load into a cascading failure and cause duplicate operations. The key insight to convey is that naive retrying makes overload worse (retry storms), so retries must be transient-only, capped, backed off and jittered, gated by a circuit breaker, bounded by timeouts, and safe under idempotency - which together make retrying a reliable recovery mechanism rather than a way to turn a struggling dependency into a dead one.
How do you design highly resilient microservices so one failing dependency can't take the system down?
I assume every dependency will fail and design to contain the blast radius by default, composing a set of resilience patterns on every cross-service interaction and backing them with architecture, observability, and testing. On each outbound call: a timeout (so a slow dependency can’t hold a request and its thread indefinitely - the primary cascade mechanism); bounded retries with exponential backoff and jitter for transient faults only (so I recover from blips without creating retry storms); a circuit breaker that trips when failures are sustained, failing fast instead of hammering a dead dependency and giving it room to recover; and bulkheads that isolate resources (thread/connection pools) per dependency so one hung dependency can only exhaust its own bounded pool, not the whole service. Where a dependency is non-critical, a fallback or graceful degradation returns a cached or default response so its failure degrades a feature rather than breaking the request - and I decide up front which features are essential and which can be shed under stress. Architecturally, I reduce synchronous coupling: interactions that don’t need an immediate response go through asynchronous messaging, so a downstream outage becomes a backlog rather than a cascading failure - the most robust protection is often not being synchronously coupled. Each service owns its data and is stateless so it can be scaled and replaced, deployed redundantly across zones with health checks so unhealthy instances are removed and restarted. I make idempotency pervasive so retries and at-least-once delivery are safe. Inbound, I add rate limiting and load shedding so overload is rejected cleanly (a fast 429) rather than collapsing everything. Underpinning it all is observability - metrics on latency, error rates, circuit-breaker state, and fallback usage, plus distributed tracing - so I can see a dependency degrading and the patterns engaging, and respond. And critically, I validate resilience with fault-injection/chaos testing that deliberately kills or slows dependencies, because resilience that’s never exercised is usually misconfigured - the first time a breaker opens for real shouldn’t be the first time it’s ever opened. In .NET I compose timeout, retry, circuit breaker, and bulkhead with the standard resilience pipeline (Polly). So highly resilient microservices come from: bounding every call with timeouts, failing fast with circuit breakers, isolating with bulkheads, retrying transient faults carefully, degrading gracefully with fallbacks, decoupling with async messaging where possible, running redundantly with health checks, making operations idempotent, shedding load under overload, observing everything, and proving it all with chaos testing - which together ensure a single failing dependency degrades gracefully and is contained, rather than cascading into a system-wide outage, treating partial failure as the normal case the architecture is built to survive.
9.5 Banking Enterprise Scenario
A banking payment system depends on fraud-detection and notification services. During peak traffic the fraud service slows. Each call has a two-second timeout, capped jittered retries for transient errors, and a circuit breaker that opens on sustained failure so payments fail fast instead of piling up; a bulkhead caps concurrent fraud calls so they can’t starve the payment path, and a cached-risk fallback lets low-risk payments proceed. Notifications are event-driven, so their backlog never touches payments. Core payment processing stays responsive throughout - failure contained by design.
Chapter Revision Notes
- Failures are constant in distributed systems - design for graceful degradation and recovery.
- Every remote call needs a timeout - the foundation that prevents cascades.
- Retry transient faults only, capped, with backoff+jitter; gate with circuit breakers to avoid retry storms.
- Circuit breakers fail fast and detect recovery; bulkheads isolate resources; fallbacks degrade gracefully.
- Health checks give orchestrators signals; fault-injection testing proves resilience actually engages.