Skip to main content
Polly is a powerful .NET resilience and transient-fault-handling library that allows developers to express resilience strategies such as Retry, Circuit Breaker, Hedging, Timeout, Rate Limiter, and Fallback in a fluent and thread-safe manner.
Polly is part of the .NET Foundation and supports .NET Standard 1.1, 2.0+, .NET Core, .NET Framework, and .NET 6+.

What is Polly?

Modern applications often depend on external services, databases, and APIs that can fail temporarily or become unavailable. Polly helps you handle these transient faults gracefully by providing a comprehensive set of resilience strategies that you can combine and configure to match your specific requirements. With Polly, you can:
  • Retry operations that fail due to transient faults
  • Break circuits when a system is under stress to prevent cascading failures
  • Add timeouts to prevent operations from hanging indefinitely
  • Rate limit requests to protect your services from overload
  • Provide fallback values when operations fail
  • Hedge requests by executing parallel operations and taking the fastest response
  • Inject chaos to test your application’s resilience

Key Features

Retry Strategy

Automatically retry failed operations with exponential backoff and jitter

Circuit Breaker

Prevent cascading failures by breaking the circuit when fault thresholds are exceeded

Timeout Management

Set time limits on operations to prevent them from running indefinitely

Rate Limiting

Control the rate of requests with multiple rate limiting algorithms

Fallback Handlers

Provide alternative values or actions when operations fail

Hedging

Execute parallel actions and use the fastest successful response

Chaos Engineering

Test your application’s resilience by injecting controlled faults

Telemetry Support

Built-in telemetry and monitoring for all resilience strategies

How Polly Works

Polly uses a resilience pipeline pattern that combines one or more resilience strategies into a unified execution flow. You build pipelines using a fluent builder API:
// Create a resilience pipeline with retry and timeout strategies
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions
    {
        MaxRetryAttempts = 3,
        Delay = TimeSpan.FromSeconds(1),
        BackoffType = DelayBackoffType.Exponential
    })
    .AddTimeout(TimeSpan.FromSeconds(10))
    .Build();

// Execute your code through the pipeline
await pipeline.ExecuteAsync(async token =>
{
    // Your code here - Polly handles retries, timeouts, etc.
    return await httpClient.GetAsync("https://api.example.com/data", token);
});

NuGet Packages

Polly is distributed as a set of NuGet packages:
PackagePurpose
Polly.CoreCore abstractions and built-in resilience strategies
Polly.ExtensionsDependency injection and telemetry integration
Polly.RateLimitingIntegration with System.Threading.RateLimiting APIs
Polly.TestingTesting utilities for Polly pipelines
PollyLegacy v7 API for backward compatibility
This documentation covers Polly v8, which introduces a new, more powerful API. If you’re using Polly v7, see the migration guide.

Why Choose Polly?

Polly is used by thousands of applications worldwide, including Microsoft’s own services. It has been refined over years of production use.
Combine multiple resilience strategies in any order to create sophisticated fault-handling behaviors tailored to your needs.
Designed for high-performance scenarios with minimal allocation and overhead. Supports async/await throughout.
Built-in support for logging, metrics, and distributed tracing to help you understand your application’s resilience.
First-class support for Microsoft.Extensions.DependencyInjection with lifecycle management and configuration.
Create custom resilience strategies to address unique requirements in your application.

Next Steps

Installation

Install Polly and set up your first project

Quickstart

Build your first resilience pipeline in minutes

Core Concepts

Learn about resilience pipelines and strategies

API Reference

Explore the complete API documentation

Build docs developers (and LLMs) love