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:
| Pattern | What it does |
|---|---|
| Timeout | Never wait forever for a dependency |
| Retry with exponential backoff + jitter | Recover from transient faults (network blips, 503) — only for idempotent operations |
| Circuit breaker | After repeated failures, fail fast for a while so the dependency can recover |
| Bulkhead | Limit concurrent calls so one slow dependency can't exhaust all threads/connections |
| Fallback | Return cached/default data when a dependency is down |
| Hedging | Send 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.