Set a wait limit on every external call (timeout); retry failures in moderation (retry); and stop calling a dependency for a while when it keeps failing (circuit breaker).
Why use it
Networks and other people’s services will fail sometimes. Without these three controls, a small glitch becomes a major incident:
No timeout: requests hang forever and resources fill up.
Blind retries: the dependency is already struggling, and you hammer it harder until it collapses.
No circuit breaker: you keep waiting out the full timeout on every request even though you know it is down.
How to do it
1. Timeouts: every external call must have one, including HTTP, databases, caches, and messaging. Most libraries default to a very long timeout or none at all.
2. Retries: in moderation
Retry only errors that may self-heal: network drops, timeouts, 502/503, 429. Retrying 400, 401, or 404 is pointless.
Retry only idempotent operations, or you may charge twice; see Idempotency.
Exponential backoff: double the wait each time (1s, 2s, 4s, …) so the dependency can catch its breath.
Add jitter: a little randomness on the interval so thousands of clients do not retry in the same second.
Cap the attempts (e.g. at most 3) and set an overall time budget.
📊 Exponential backoff: how long to wait before each retry
Before 1st retry
1 s
Before 2nd retry
2 s
Before 3rd retry
4 s
Before 4th retry
8 s
Example config: interval doubles each time; production use also adds random jitter.
3. Circuit breaker: three states.
🧭 How the circuit breaker handles one call
📞About to call a downstream service
↓
Is the breaker open?
YesReject immediately, use the fallback
↓
Send the request (with a timeout)
↓
Succeeded?
FailedRecord a failure; trip if the rate is too high
↓
Return the result
State
Behavior
Closed (normal)
Requests go out; failure rate is tracked
Open (tripped)
Failure rate too high; reject for a while without sending
Half-open
After a while, let a few probe requests through; succeed → recover, fail → stay open
4. Fallback: when the breaker is open, return a “good enough” substitute—e.g. cached data—instead of failing the whole page.
Component comparison
No component data for this language yet. On the home page choose "Decide later" and let AI recommend one.
Microsoft.Extensions.Http.Resilience
Built into the frameworkOpsLow
Microsoft's official HttpClient resilience package, built on Polly; a single AddStandardResilienceHandler call adds timeouts, retries, and circuit breaking.
Best forNew .NET projects that call external HTTP services.
Avoid whenWhat needs protection is not an HTTP call, or the project is stuck on a very old .NET version.
Pros
Defaults include a total timeout, jittered retry, a circuit breaker, and a per-try timeout
With the HttpClient factory, almost no extra code is required
Microsoft maintains it, so a new project can prefer it
Cons
It only covers HttpClient, not databases or message queues
The default settings may not fit, so understand them before you tune
Non-idempotent POSTs are retried by default, which can charge the user twice
The long-standing resilience library for .NET; freely combine timeout, retry, circuit breaker, rate limiting, and other policies on any code, not just HTTP.
Best forC# projects that need to protect non-HTTP calls or need finely customized policies.
Avoid whenYou only want standard protection on a plain HttpClient; the official Resilience package is easier.
Pros
It can protect any code, not only outbound HTTP calls
Timeouts, retries, and circuit breakers can be combined as needed
There is plenty of material, and older projects often already use it
Cons
v7 and v8 are written differently, so online tutorials are easy to mix up
A bad setup, such as retries with no upper bound, can cause an incident
You attach it at every call site yourself, and it is easy to miss one