Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

Polly

> DevOps
Open source

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Iso

14.2K stars0 likes2 views
WebsiteGitHub

About

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Iso

Polly

[!IMPORTANT] Polly now participates in the Open Source Maintenance Fee (OSMF). Starting November 16, 2026, companies that earn at least US $20,000 from a product or project that uses Polly will be asked to pay a US $20/month maintenance fee to help fund Polly's ongoing upkeep. The source code stays free and open, and individuals, hobbyists, and organizations below the threshold owe nothing. Read the announcement: Introducing the Open Source Maintenance Fee for Polly · Learn about the OSMF · Become a sponsor

Polly is a .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.

NuGet NuGet Downloads

We are a member of the .NET Foundation!

Keep up to date with new feature announcements, tips & tricks, and other news through www.thepollyproject.org

[!IMPORTANT] This documentation describes the new Polly v8 API. If you are using the v7 API, please refer to the previous version of the documentation.

NuGet Packages

Package Latest Version About
Polly.Core The core abstractions and built-in strategies.
Polly.Extensions Telemetry and dependency injection support.
Polly.RateLimiting Integration with System.Threading.RateLimiting APIs.
Polly.Testing Testing support for Polly libraries.
Polly This package contains the legacy API exposed by versions of the Polly library before version 8.

Documentation

This README aims to give a quick overview of some Polly features - including enough to get you started with any resilience strategy. For deeper detail on any resilience strategy, and many other aspects of Polly, be sure also to check out pollydocs.org.

Quick start

To use Polly, you must provide a callback and execute it using resilience pipeline. A resilience pipeline is a combination of one or more resilience strategies such as retry, timeout, and rate limiter. Polly uses builders to integrate these strategies into a pipeline.

To get started, first add the Polly.Core package to your project by running the following command:

bash
dotnet add package Polly.Core

You can create a ResiliencePipeline using the ResiliencePipelineBuilder class as shown below:

cs
// Create an instance of builder that exposes various extensions for adding resilience strategies
ResiliencePipeline pipeline = new ResiliencePipelineBuilder()
    .AddRetry(new RetryStrategyOptions()) // Add retry using the default options
    .AddTimeout(TimeSpan.FromSeconds(10)) // Add 10 seconds timeout
    .Build(); // Builds the resilience pipeline

// Execute the pipeline asynchronously
await pipeline.ExecuteAsync(static async token => { /* Your custom logic goes here */ }, cancellationToken);

Dependency injection

If you prefer to define resilience pipelines using IServiceCollection, you'll need to install the Polly.Extensions package:

bash
dotnet add package Polly.Extensions

You can then define your resilience pipeline using the AddResiliencePipeline(...) extension method as shown:

…

Resilience strategies

Polly provides a variety of resilience strategies. Alongside the comprehensive guides for each strategy, the wiki also includes an overview of the role each strategy plays in resilience engineering.

Polly categorizes resilience strategies into two main groups:

Reactive

These strategies handle specific exceptions that are thrown, or results that are returned, by the callbacks executed through the strategy.

Strategy Premise AKA Mitigation
Retry family Many faults are transient and may self-correct after a short delay. Maybe it's just a blip Allows configuring automatic retries.
Circuit-breaker family When a system is seriously struggling, failing fast is better than making users/callers wait.

Protecting a faulting system from overload can help it recover.
Stop doing it if it hurts

Give that system a break
Breaks the circuit (blocks executions) for a period, when faults exceed some pre-configured threshold.
Fallback Things will still fail - plan what you will do when that happens. Degrade gracefully Defines an alternative value to be returned (or action to be executed) on failure.
Hedging Things can be slow sometimes, plan what you will do when that happens. Hedge your bets Executes parallel actions when things are slow and waits for the fastest one.

Proactive

Unlike reactive strategies, proactive strategies do not focus on handling errors, but the callbacks might throw or return. They can make proactive decisions to cancel or reject the execution of callbacks.

Strategy Premise AKA Prevention
Timeout Beyond a certain wait, a success result is unlikely. Don't wait forever Guarantees the caller won't have to wait beyond the timeout.
Rate Limiter Limiting the rate a system handles requests is another way to control load.

This can apply to the way your system accepts incoming calls, and/or to the way you call downstream services.
Slow down a bit, will you? Constrains executions to not exceed a certain rate.

Visit resilience strategies docs to explore how to configure individual resilience strategies in more detail.

Retry

…

If all retries fail, a retry strategy rethrows the final exception back to the calling code.

For more details, visit the retry strategy documentation.

Circuit Breaker

…

For more details, visit the circuit breaker strategy documentation.

Fallback

…

For more details, visit the fallback strategy documentation.

Hedging

…

If all hedged attempts fail, the hedging strategy will either re-throw the original exception or return the original failed result to the caller.

For more details, visit the hedging strategy documentation.

Timeout

The timeout resilience strategy assumes delegates you execute support co-operative cancellation. You must use Execute/Async(...) overloads taking a CancellationToken, and the executed delegate must honor that CancellationToken.

…

Timeout strategies throw TimeoutRejectedException when a timeout occurs.

For more details, visit the timeout strategy documentation.

Rate Limiter

…

Rate limiter strategy throws RateLimiterRejectedException if execution is rejected.

For more details, visit the rate limiter strategy documentation.

Chaos engineering

Starting with version 8.3.0, Polly has integrated Simmy, a chaos engineering library, directly into its core. For more information, please refer to the dedicated chaos engineering documentation.

Next steps

To learn more about Polly, visit pollydocs.org.

Samples

  • Samples: Samples in this repository that serve as an introduction to Polly.
  • Polly-Samples: Contains practical examples for using various implementations of Polly. Please feel free to contribute to the Polly-Samples repository in order to assist others who are either learning Polly for the first time, or are seeking advanced examples and novel approaches provided by our generous community.
  • Microsoft's eShopOnContainers project: Sample project demonstrating a .NET Micro-services architecture and using Polly for resilience.

Sponsors

Thanks to the following companies for sponsoring the ongoing development of Polly.

  • .NET on AWS Open Source Software Fund
  • Microsoft's Free and Open Source Software Fund
  • GitHub's Secure Open Source Fund

Open Source Maintenance Fee

Polly participates in the Open Source Maintenance Fee (OSMF). Starting November 16, 2026, companies that earn at least US $20,000 from a product or project that uses Polly are asked to pay a US $20/month maintenance fee, regardless of how many of their projects use Polly. This helps fund the ongoing work of keeping the project secure, current, and well maintained.

The source code remains free and open under its existing license. Individuals, hobbyists, students, non-profits, and organizations below the revenue threshold owe nothing. For full details, see the announcement post and the OSMF FAQ.

Help support this project by becoming a sponsor through GitHub Sponsors.

License

Licensed under the terms of the New BSD License

Issues· 1 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#circuit-breakercircuit-breaker-patterndotnetfault-handler

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理