Strategy Categories
Polly organizes resilience strategies into two main categories:Reactive Strategies
Handle specific exceptions or results returned by callbacks. These strategies respond to failures after they occur.
Proactive Strategies
Make proactive decisions to cancel or reject callback execution before failures occur, like rate limiting or timeouts.
Built-in Reactive Strategies
Reactive strategies respond to failures by handling specific exceptions or results:Retry - Handle transient failures
Retry - Handle transient failures
Premise: Many faults are transient and may self-correct after a short delay.How it helps: Automatically retries failed operations with configurable delay strategies (constant, linear, exponential with jitter).Use when: Network calls fail temporarily, database connections drop, or services experience brief outages.Learn more about Retry →
Circuit Breaker - Protect failing systems
Circuit Breaker - Protect failing systems
Premise: When a system is seriously struggling, failing fast is better than making users wait. Protecting a faulting system from overload helps it recover.How it helps: Blocks executions when failures exceed a threshold, then periodically allows test requests to check if the system has recovered.Use when: You need to prevent cascading failures and give downstream services time to recover.Learn more about Circuit Breaker →
Fallback - Degrade gracefully
Fallback - Degrade gracefully
Premise: Things will still fail—plan what you will do when that happens.How it helps: Defines an alternative value to return or action to execute when operations fail.Use when: You can provide default data, cached responses, or alternative implementations.Learn more about Fallback →
Hedging - Handle slow operations
Hedging - Handle slow operations
Premise: Things can be slow sometimes—plan what you will do when that happens.How it helps: Executes parallel actions when things are slow and returns the fastest successful result.Use when: You have multiple endpoints that can serve the same data, and latency is critical.Learn more about Hedging →
Built-in Proactive Strategies
Proactive strategies prevent failures by controlling execution:Timeout - Don't wait forever
Timeout - Don't wait forever
Premise: Beyond a certain wait time, a successful result is unlikely.How it helps: Guarantees the caller won’t wait beyond the timeout period.Use when: You need to enforce time limits on operations to maintain system responsiveness.Learn more about Timeout →
Rate Limiter - Control request rates
Rate Limiter - Control request rates
Premise: Limiting the rate a system handles requests is another way to control load on your system or downstream services.How it helps: Constrains executions to not exceed a certain rate.Use when: You need to throttle incoming requests or limit the rate of calls to downstream APIs.Learn more about Rate Limiter →
Strategy Availability
Not all strategies are available for both generic and non-generic pipelines:| Strategy | ResiliencePipelineBuilder | ResiliencePipelineBuilder<T> |
|---|---|---|
| Circuit Breaker | ✅ | ✅ |
| Fallback | ❌ | ✅ |
| Hedging | ❌ | ✅ |
| Rate Limiter | ✅ | ✅ |
| Retry | ✅ | ✅ |
| Timeout | ✅ | ✅ |
Fallback and Hedging strategies require a result type (
T) because they need to return or handle specific result values.Adding Strategies to Pipelines
Each resilience strategy provides extension methods for adding it to pipeline builders:Fault Handling with Predicates
Reactive strategies use theShouldHandle predicate to determine which failures to handle. You can configure this in two ways:
Using Switch Expressions (Recommended)
Switch expressions provide maximum flexibility:Using PredicateBuilder
ThePredicateBuilder provides a fluent API for simpler scenarios:
Asynchronous Predicates
You can use async predicates for advanced scenarios like checking response bodies:Combining Strategies
You can combine multiple strategies in a single pipeline. The order matters:Strategy Configuration Best Practices
Use collections for exception types
Instead of chaining multiple
.Handle<T>() calls, group exceptions:Define separate strategies for different failure domains
Don’t mix network failures with parsing failures in one strategy:
Quick Reference
Here’s a quick guide to choosing the right strategy:| Scenario | Recommended Strategy |
|---|---|
| Network call might fail temporarily | Retry |
| Operation might take too long | Timeout |
| Service is completely down | Circuit Breaker |
| Need to return default data on failure | Fallback |
| Want fastest response from multiple sources | Hedging |
| Need to control request rate | Rate Limiter |
| Multiple concurrent requests | Concurrency Limiter |
Next Steps
Resilience Pipelines
Learn how to compose strategies into pipelines
Resilience Context
Understand how to share data across strategy execution
Retry Strategy
Deep dive into the retry strategy
Circuit Breaker Strategy
Explore circuit breaker patterns