The .NET Resilience Library
We'll cover the core concepts of resilience engineering, the different Polly policies, and practical techniques for building fault-tolerant .NET applications.
Polly โ The .NET Resilience Library
Technical session + live demo + Q&A
Polly is a free .NET code library that automatically handles small, temporary failures for you โ the little "glitches" that happen when your app talks to something else over a network, like a database or another website.
The user never even notices.
Retry, break failing connections, set timeouts, provide fallbacks, limit concurrency, and combine multiple strategies together.
REST & Payment APIs, SQL Server, Redis, RabbitMQ, Azure/AWS services, and any network or file-system call.
In software engineering, resilience means a system can keep working even when something goes wrong โ recovering quickly instead of crashing or stopping completely.
The bridge is built so strong it can handle strong winds without any damage.
The bridge can bend during a big storm, absorb the impact, and return to normal instead of collapsing.
Each rule (retry, timeout, circuit breaker) was its own separate "Policy" object. Combining several required extra wrapping โ slower and heavier on memory.
A ResiliencePipeline is a single, unified "assembly line" โ one faster, lighter-weight pipeline replacing all the separate Policy objects.
If Service B slows down, the circuit breaker cuts the connection so Service A doesn't exhaust its own resources waiting.
Instead of a raw 500 error, a failed recommendations engine can fall back to a cached, generic product list.
Polly prevents a single user (tenant) from crashing an entire application by consuming all its network resources.
If an operation fails, don't give up immediately โ wait a moment and try it again, because the problem might already be gone.
Attempt 1 โ 500 Error
Attempt 2 โ 503 Error
Attempt 3 โ 200 OK
Always waits the same amount of time.
2s โ 2s โ 2s
Increases delay after each failure. Reduces server pressure.
1s โ 2s โ 4s โ 8s
Prevents 1000 clients from retrying at exactly the same time (Thundering Herd).
1.2s โ 2.8s โ 4.5s
Give an operation a maximum amount of time to finish. If it hasn't responded by then, stop waiting and treat it as failed โ instead of waiting forever.
Waiting... Waiting... Waiting...
Polly stops it. Prevents hung requests and frees resources.
Named after the electrical circuit breaker in your house. If a service keeps failing, stop sending it requests for a while so it can recover.
Current flows normally. Requests pass through โ everything is healthy.
Tripped. All requests are blocked instantly and fail fast, giving the downstream service time to recover.
After cool-down, one "test" request is let through. Success โ closes again. Failure โ trips back open.
Have a "Plan B" answer ready. If every attempt to get the real result fails, give the user something useful instead of an error screen.
Instead of throwing an exception, return:
Controls requests per time period.
Example: server allows 100 requests/minute โ Polly ensures you don't exceed the quota.
Controls simultaneous requests โ the v8 successor to Bulkhead Isolation.
Example: only 10 requests at once; extra requests wait.
Sends a backup request when the original is slow โ the fastest response wins.
Trade-off: uses more resources; best for read-only or geo-distributed services.
A single call can pass through several protective layers, like security checkpoints at an airport โ each layer only steps in if the ones before it couldn't fix the problem.
Now every request from this client automatically flows through the full Polly pipeline.
| Strategy | Use When... | Real-World Analogy |
|---|---|---|
| Retry | Temporary failures like timeouts or 503 responses | Redialing a dropped phone call |
| Circuit Breaker | A downstream service is repeatedly failing | An electrical breaker tripping during a surge |
| Timeout | Operations might hang indefinitely | Hanging up after 10 minutes on hold |
| Fallback | A default response or cached data is acceptable | Waiter suggesting an alternate dish |
| Hedging | Low latency is critical; duplicate requests are OK | Booking two rideshares, keeping whichever arrives first |
| Rate / Concurrency Limiter | You must respect API limits or protect resources | A bouncer letting in 5 people per minute |
The same strategies protect very different systems, at very different scales.
A 3-second DB blip caused 50,000 requests to retry at once, crashing the database. Fix: exponential backoff + jitter smoothed retries across time.
A bank API slowed to 45s, exhausting all app threads. Fix: Timeout (2s) + Circuit Breaker (60s open) + Fallback to an offline queue.
Every team writing custom retry code caused fragmentation. Fix: Microsoft embedded Polly v8 as a first-class citizen across Azure SDKs.
User โ ASP.NET Core API โ Resilience Pipeline (Retry ยท Timeout ยท Circuit Breaker ยท Fallback) โ SQL Server / Payment API / Redis
Every downstream call is protected the same consistent way โ one shared set of Polly rules.
Polly โ The .NET Resilience Library
Since v5.0 in October 2016, Polly has been governed as a community-driven open-source project under the .NET Foundation โ the same organization stewarding core .NET infrastructure.
Official Docs: pollydocs.org
GitHub: App-vNext/Polly