Roadmap › Microservices & System Design with .NET › Module: Running Microservices in Production
Lessons in this course (9)

7. Resilience — retries, timeouts, circuit breakers

Intermediate★ Must knowLesson 7 of 9

In a distributed system something is always failing. Patterns:

PatternWhat it does
TimeoutNever wait forever for a dependency
Retry with exponential backoff + jitterRecover from transient faults (network blips, 503) — only for idempotent operations
Circuit breakerAfter repeated failures, fail fast for a while so the dependency can recover
BulkheadLimit concurrent calls so one slow dependency can't exhaust all threads/connections
FallbackReturn cached/default data when a dependency is down
HedgingSend a second request if the first is slow, use the first answer
csharp
builder.Services.AddHttpClient<PaymentClient>()
    .AddResilienceHandler("payments", b =>
    {
        b.AddTimeout(TimeSpan.FromSeconds(10));
        b.AddRetry(new HttpRetryStrategyOptions { MaxRetryAttempts = 3, BackoffType = DelayBackoffType.Exponential, UseJitter = true });
        b.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions { FailureRatio = 0.5, BreakDuration = TimeSpan.FromSeconds(30) });
    });

Also: health checks (AddHealthChecks(), /health/live and /health/ready for Kubernetes probes) and graceful degradation.