ConfigsMay 23, 2026·2 min read

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.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Polly Overview
Universal CLI install command
npx tokrepo install 40a83ed4-56c4-11f1-9bc6-00163e2b0d79

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets