# Polly — .NET Resilience and Transient Fault Handling > A .NET library that lets developers express retry, circuit breaker, timeout, bulkhead isolation, and fallback policies in a fluent, thread-safe API. ## Install Save in your project root: # Polly — .NET Resilience and Transient Fault Handling ## Quick Use ```bash dotnet add package Polly ``` ```csharp var pipeline = new ResiliencePipelineBuilder() .AddRetry(new RetryStrategyOptions { MaxRetryAttempts = 3 }) .AddTimeout(TimeSpan.FromSeconds(10)) .Build(); await pipeline.ExecuteAsync(async ct => await httpClient.GetAsync(url, ct)); ``` ## Introduction Polly is a .NET resilience and transient fault handling library. It provides a fluent API for defining policies such as retry, circuit breaker, timeout, rate limiter, and fallback that wrap unreliable calls to external services, databases, or any operation that can fail transiently. ## What Polly Does - Retries failed operations with configurable backoff strategies - Implements circuit breaker patterns to stop cascading failures - Enforces timeouts on long-running operations - Provides bulkhead isolation to limit concurrent resource usage - Combines multiple strategies into resilience pipelines ## Architecture Overview Polly v8 introduces a pipeline-based architecture built on ResiliencePipelineBuilder. Each strategy (retry, circuit breaker, timeout) is a composable middleware layer. The pipeline executes strategies in order, wrapping the inner delegate. The library uses a non-allocating execution path for hot paths and integrates with Microsoft.Extensions.Resilience for dependency injection in ASP.NET Core. ## Self-Hosting & Configuration - Install the core package: `dotnet add package Polly` - For DI integration: `dotnet add package Microsoft.Extensions.Resilience` - Register pipelines in Program.cs via `builder.Services.AddResiliencePipeline()` - Configure strategies through option objects or appsettings.json - Works with .NET Standard 2.0+ and .NET 6 through .NET 9 ## Key Features - Fluent builder API for composing resilience strategies - Built-in telemetry and metering via .NET metrics - Hedging strategy for speculative parallel execution - Rate limiter integration with System.Threading.RateLimiting - Thread-safe and designed for high-throughput scenarios ## Comparison with Similar Tools - **Microsoft.Extensions.Http.Resilience** — built on Polly; provides opinionated HttpClient resilience defaults - **Resilience4j (Java)** — similar patterns for the JVM ecosystem; no .NET support - **Steeltoe** — cloud-native .NET framework with circuit breaker; broader scope, less focused - **Hystrix (.NET port)** — Netflix circuit breaker; no longer actively maintained - **Custom retry loops** — ad hoc try/catch patterns; no composability, harder to test ## FAQ **Q: What changed between Polly v7 and v8?** A: Polly v8 replaced the policy-based API with a pipeline-based architecture using ResiliencePipelineBuilder. It is simpler, more performant, and integrates natively with Microsoft.Extensions. **Q: Can I use Polly with HttpClient?** A: Yes. The Microsoft.Extensions.Http.Resilience package provides AddStandardResilienceHandler() that configures HttpClient with Polly-based retry, circuit breaker, and timeout out of the box. **Q: Does Polly support async operations?** A: Yes. All resilience pipelines support both synchronous and asynchronous execution via ExecuteAsync with CancellationToken support. **Q: How do I monitor Polly behavior in production?** A: Polly v8 emits .NET metrics and supports TelemetryListeners. You can export these to OpenTelemetry, Application Insights, or any metrics backend. ## Sources - https://github.com/App-vNext/Polly - https://www.thepollyproject.org/ --- Source: https://tokrepo.com/en/workflows/asset-40a83ed4 Author: AI Open Source