By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Resilience Engineering in .NET 8: Polly Pipelines in Practice | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > Resilience Engineering in .NET 8: Polly Pipelines in Practice | HackerNoon
Computing

Resilience Engineering in .NET 8: Polly Pipelines in Practice | HackerNoon

News Room
Last updated: 2026/02/13 at 6:56 PM
News Room Published 13 February 2026
Share
Resilience Engineering in .NET 8: Polly Pipelines in Practice | HackerNoon
SHARE

As a developer/architect, you will often need to build or consume a third-party system via an API channel. In this article, we primarily focus on the best way to consume APIs to tackle network or API system issues through .NET Core using the Polly open-source package.

Why Do We Need It?

In small or large micro services or distributed environments, systems are frequently connected to read or push the data in terms of API, message queues, or asynchronous HTTP calls.

When we deal with calling external services, network issues happen all the time. Since services will fail one time or another,  we always need safety protection.

What is Polly?

Polly is a resilience and transient fault handling library. It provides implementation of auto-retry, Circuit breaker, and more resilience features through fluent configuration.

Microsoft has introduced Microsoft.Extensions.Resilience and Microsoft.Extensions.Http.Resilience as new resilience APIs optimized for .NET 8, building on the Polly concepts.

These new libraries,” Http Resilience,”  are based on the Polly library, a widely recognized open-source project.

These are now the recommended libraries for HTTP resilience in .NET 8 apps.

Learn more about the packages. https://learn.microsoft.com/en-us/dotnet/core/resilience/http-resilience

I would suggest using Polly if your .NET version is <.Net8

Implementation

In this article, we are going to explain the traditional and modern approaches through Polly.

  1. Retry through the manual way
  2. Retry through Resilience Pipelines (Polly)– Auto Retries

As of now (Feb 2026), we have .NET 10 in preview release; for that reason, I am building through .NET 8.

n

n Web API - .NET version

API Controller

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
&nbsp;&nbsp;&nbsp;&nbsp;private static readonly string[] Summaries = new[]
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
&nbsp;&nbsp;&nbsp;&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;private readonly ILogger<WeatherForecastController> _logger;
&nbsp;&nbsp;&nbsp;&nbsp;public WeatherForecastController(ILogger<WeatherForecastController> logger)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_logger = logger;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;[HttpGet(Name = "GetWeatherForecast")]
&nbsp;&nbsp;&nbsp;&nbsp;public IEnumerable<WeatherForecast> Get()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Enumerable.Range(1, 5).Select(index => new WeatherForecast
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TemperatureC = Random.Shared.Next(-20, 55),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Summary = Summaries[Random.Shared.Next(Summaries.Length)]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.ToArray();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

Testing API in Postman Postman Testing

Let’s throw the exception in the get method

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception("Error in dotnet 8");
}

Test in Postman Postman Testing

Let’s build another API to consume this API.

Swagger

It’s running on the endpoint: https://localhost:7050/

n Swagger UI

Let’s proceed with implementing retries.

  1. Retry through the manual way

   Program.cs
   // This method gets called by the runtime. Use this method to add services to the container.
   builder.Services.AddHttpClient("errorApiClient", client =>
   {
   &nbsp;&nbsp;&nbsp;&nbsp;client.BaseAddress = new Uri("https://localhost:7009/");
   });
   Pollycontroller.cs
   [Route("api/[controller]")]
   [ApiController]
   public class PollyController : ControllerBase
   {
   &nbsp;&nbsp;&nbsp;&nbsp;private readonly IHttpClientFactory _httpClientFactory;
   &nbsp;&nbsp;&nbsp;&nbsp;public PollyController(IHttpClientFactory httpClientFactory)
   &nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this._httpClientFactory = httpClientFactory;
   &nbsp;&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;// GET api/values
   &nbsp;&nbsp;&nbsp;&nbsp;[HttpGet]
   &nbsp;&nbsp;&nbsp;&nbsp;public async Task<IActionResult> Get()
   &nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder sbresult = new StringBuilder();
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var result = "";
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = await GetValues();
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (result.Contains("Error in dotnet"))
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new Exception("Error");
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;catch
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Retry 3 times
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var count = 1; count < 3; count++)
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Ok(result);
   &nbsp;&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;private async Task<string> GetValues()
   &nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var client = _httpClientFactory.CreateClient("errorApiClient");
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var response = await client.GetAsync("weatherforecast");
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return await response.Content.ReadAsStringAsync();
   &nbsp;&nbsp;&nbsp;&nbsp;}

Postman Postman Testing

  1. Retry through Resilience Pipelines– Auto Retries

    Install Package:  “Microsoft.Extensions.Http.Resilience”

    n Project Template

   Program.cs
   // This method gets called by the runtime. Use this method to add services to the container.
   &nbsp;
   builder.Services.AddHttpClient("errorApiClient", client =>
   {
   &nbsp;&nbsp;&nbsp;&nbsp;client.BaseAddress = new Uri("https://localhost:7009/");
   }).AddResilienceHandler("retry-pipeline", builder =>
   {
   &nbsp;&nbsp;&nbsp;&nbsp;builder.AddRetry(new HttpRetryStrategyOptions
   &nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxRetryAttempts = 3,
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delay = TimeSpan.FromSeconds(2),
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BackoffType = DelayBackoffType.Exponential,
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OnRetry = args =>
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$"[Retry] Attempt #{args.AttemptNumber + 1} | " +
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$"Reason: {args.Outcome.Exception?.Message ?? args.Outcome.Result?.StatusCode.ToString()}"
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ValueTask.CompletedTask;
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
   &nbsp;&nbsp;&nbsp;&nbsp;});
   });
   PollyController.cs

Remove the retry code in the exception block.

Postman

Postman Testing

n

n

Conclusion

The retry feature is very useful when you try to connect to any other system. Without this, you typically write duplicated try/catch logic everywhere. This package will also address the problems such as “Circuit breaker, Timeout, Rate limiting”.

I hope you learned the importance and implementation of auto-retries in the .NET 8 ecosystem.

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article UK government calls for review into mobile market | Computer Weekly UK government calls for review into mobile market | Computer Weekly
Next Article Marvel&apos;s Spider-Man 2 Leaps Onto PS Plus in February Marvel's Spider-Man 2 Leaps Onto PS Plus in February
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Today&apos;s NYT Connections: Sports Edition Hints, Answers for Feb. 14 #509
Today's NYT Connections: Sports Edition Hints, Answers for Feb. 14 #509
News
The 3-Second War: How to Engineer Ads That Stop the Scroll (Free AI Prompt) | HackerNoon
The 3-Second War: How to Engineer Ads That Stop the Scroll (Free AI Prompt) | HackerNoon
Computing
The Best Movies to Watch on Netflix Right Now (Feb. 13-20, 2026)
The Best Movies to Watch on Netflix Right Now (Feb. 13-20, 2026)
News
China’s JD.com locked in heated  battle for food delivery supremacy as regulators urge fair competition · TechNode
China’s JD.com locked in heated  battle for food delivery supremacy as regulators urge fair competition · TechNode
Computing

You Might also Like

The 3-Second War: How to Engineer Ads That Stop the Scroll (Free AI Prompt) | HackerNoon
Computing

The 3-Second War: How to Engineer Ads That Stop the Scroll (Free AI Prompt) | HackerNoon

9 Min Read
China’s JD.com locked in heated  battle for food delivery supremacy as regulators urge fair competition · TechNode
Computing

China’s JD.com locked in heated  battle for food delivery supremacy as regulators urge fair competition · TechNode

4 Min Read
Smart Pinterest Board Names: Keyword-Rich, On-Brand, Memorable
Computing

Smart Pinterest Board Names: Keyword-Rich, On-Brand, Memorable

3 Min Read
Why BitMEX’s 70,000 USDT Rewards Mark a Shift in Cross-Asset Trading Access | HackerNoon
Computing

Why BitMEX’s 70,000 USDT Rewards Mark a Shift in Cross-Asset Trading Access | HackerNoon

8 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?