Building Resilient APIs with ASP.NET Core and Polly
Backend services frequently depend on APIs, databases and other remote systems that can fail temporarily.
In modern .NET applications, HTTP resilience can be configured through Microsoft.Extensions.Http.Resilience, which uses Polly underneath.
Why Resilience Matters
Temporary network failures should not automatically become application failures. At the same time, retrying indefinitely can make an outage worse.
A resilience pipeline lets the application combine strategies such as retries, timeouts and circuit breakers in a controlled way.
Standard Resilience Handler
Install the HTTP resilience package:
dotnet add package Microsoft.Extensions.Http.Resilience
Then configure the client:
builder.Services
.AddHttpClient("WeatherClient", client =>
{
client.BaseAddress =
new Uri("https://example.com");
})
.AddStandardResilienceHandler();
What the Standard Pipeline Provides
The standard HTTP resilience handler combines several protections, including retry, circuit breaking and timeout strategies.
More advanced applications can use
AddResilienceHandler() to build a customized resilience
pipeline.
Production Considerations
- Retry only operations that are safe to retry.
- Use timeouts so failed dependencies do not consume resources indefinitely.
- Use circuit breakers to reduce pressure on unhealthy dependencies.
- Log retry and circuit-breaker events for production diagnostics.
- Measure dependency latency and error rates.
Key Takeaway
Resilience is not simply about adding retries. A good resilience strategy limits the impact of temporary failures while preventing an unhealthy dependency from destabilizing the rest of the application.
6 min read • Published Jul 15, 2025
Back to Writing