C# Retry Pattern Simple Implementaion

What is Retry pattern?

Kamal Rathnayake
1 min readJun 21, 2021

You cannot guarantee your web services to be running 100% of the time. At most you’ll be able to achieve 99.9% of availability.

In modern application architectures whether it be micro-services, containerized applications running in the cloud failures are inevitable. That’s why it’s really important to consider implementing resiliency and transient fault handling patterns in all your applications.

Applications that communicate over networks like talking to a database or an API are subject to transient failures. These temporary faults cause lesser amounts of downtime due to timeouts, overloaded resources, networking hiccups, and other problems that come and go and are hard to reproduce. These failures are usually self-correcting.

Implementing resiliency patterns like retry would heavily improve the user experience and the developer troubles you might get on your way. :)

An example from C#

This is an example written using C# language demonstrating the concept of the pattern. Please be careful if you decide to use this in production.

More advanced stuff to look into,

There’s few advanced patterns you should look into as well such as Circuit Breaker, and Exponential back-off would be few of them.

Hope you’ve learned something new today. :D

--

--

Kamal Rathnayake

Lead Software Engineer with 6 years of experience in the industry. Writing for fun!