<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Taofeek Akintola on Medium]]></title>
        <description><![CDATA[Stories by Taofeek Akintola on Medium]]></description>
        <link>https://medium.com/@taofeekcomsc?source=rss-5fd7ac70ce4c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YN49aQVddycsz4N3pK1MHA.jpeg</url>
            <title>Stories by Taofeek Akintola on Medium</title>
            <link>https://medium.com/@taofeekcomsc?source=rss-5fd7ac70ce4c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:18:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taofeekcomsc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Resilient Applications with Polly Retry Strategy in C#]]></title>
            <link>https://medium.com/@taofeekcomsc/building-resilient-applications-with-polly-retry-strategy-in-c-95b620dbb936?source=rss-5fd7ac70ce4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/95b620dbb936</guid>
            <dc:creator><![CDATA[Taofeek Akintola]]></dc:creator>
            <pubDate>Sat, 17 Feb 2024 15:07:14 GMT</pubDate>
            <atom:updated>2024-02-17T15:07:14.227Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JFE6uxP2wD6aU--NcDqkg.jpeg" /></figure><p><strong>Introduction<br></strong>In today’s interconnected and distributed systems, building resilient applications is crucial to ensure stability and reliability. <a href="https://learn.microsoft.com/en-us/dotnet/core/resilience/?tabs=dotnet-cli">Resilient application development</a> involves designing systems that can gracefully handle failures and recover from errors without compromising user experience. One powerful tool for implementing resilience patterns in C# applications is the <a href="https://github.com/App-vNext/Polly">Polly </a>library, which provides a robust framework for defining and executing retry strategies. In this article, we’ll explore how to leverage Polly’s retry strategy to build resilient applications in C#, along with practical coding examples.</p><p><strong>Understanding Polly Retry Strategy<br></strong>Polly is a .NET resilience and transient-fault-handling library that helps developers handle faults and failures in their applications. The retry policy provided by Polly allows developers to define flexible retry strategies for handling transient errors, such as network timeouts, temporary service outages, or database connectivity issues. The retry policy retries the execution of an operation a specified number of times with configurable retry intervals.</p><p><strong>Implementing Retry Strategy with Polly<br></strong>Let’s dive into how we can implement a retry strategy using Polly in a C# application. Suppose we have a method that makes an HTTP request to an external service, and we want to retry the request in case of transient failures.</p><ol><li>Install the Polly NuGet package</li></ol><pre>Install-Package Polly</pre><p>2. Define a retry policy using Polly</p><pre><br>using Polly;<br>// Define a retry policy with exponential backoff<br>var retryPolicy = Policy<br> .Handle&lt;HttpRequestException&gt;()<br> .WaitAndRetryAsync(<br> retryCount: 3,<br> sleepDurationProvider: retryAttempt =&gt; TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),<br> onRetry: (exception, retryCount) =&gt;<br> {<br> // Log or handle the retry attempt<br> Console.WriteLine($&quot;Retrying request. Retry count: {retryCount}&quot;);<br> });</pre><p>3. Use the retry policy to execute the operation</p><pre>try<br>{<br> // Execute the operation with retry policy<br> await retryPolicy.ExecuteAsync(async () =&gt;<br> {<br> // Make HTTP request<br> HttpResponseMessage response = await httpClient.GetAsync(&quot;https://api.example.com/data&quot;);<br> response.EnsureSuccessStatusCode();<br> <br> // Process response<br> string responseBody = await response.Content.ReadAsStringAsync();<br> Console.WriteLine($&quot;Response: {responseBody}&quot;);<br> });<br>}<br>catch (HttpRequestException ex)<br>{<br> // Handle exception or log error<br> Console.WriteLine($&quot;Error: {ex.Message}&quot;);<br>}</pre><p>In this example, the `<em>Handle&lt;HttpRequestException&gt;()</em>` method specifies the type of exception to handle, and the `<em>WaitAndRetryAsync</em>` method defines the retry policy with exponential backoff. The `<em>onRetry</em>` action is invoked on each retry attempt, where you can log or handle the retry logic.</p><p><strong>Conclusion<br></strong>By leveraging the Polly library and its retry strategy, developers can build resilient applications that can gracefully handle transient failures and recover from errors. The flexible retry policies provided by Polly allow for fine-grained control over retry behavior, enabling developers to tailor resilience strategies to specific use cases. Incorporating Polly into your C# applications empowers you to create robust and reliable systems that deliver a seamless user experience even in the face of adverse conditions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95b620dbb936" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>