Skip to main content

Azure Design patterns: Self-Healing & Transient fault handling

I will start a series of posts about the core design patterns that you need to take into consideration when you start to work with Microsoft Azure and the cloud in general.
These principles are important in a cloud application, even if most of them are known from classical on-premises development. Even if most of them are known, we don’t apply them for on-premises system all the time.
In a cloud environment, it is possible for example to have for 10ms a connectivity problem with another service that you are using. It means that you would need a retry policy in-place that would automatically try to reconnect to the service.
Cases like this need to be covered by your application that is running in the cloud. Take into consideration that you need to take all of this into consideration for lift and shift cases, too.

Self-Healing & Transient fault handling
The today post it is dedicated to self-healing topic. This is not SF, and you don’t need to be Netflix to have a self-healing mechanism. You can do small things at the application level that can improve drastically the capability of your system to recover after failures, especially when you work with a distributed system.  
When you run on top of Azure, there are many external services and dependencies that are used by your system. If one of them has a connectivity issue or is down for a few seconds, you need a mechanism that can recover from this failure and minimize data loss.

There are three things that you need to check to be able to have a self-healing system

  • Detect: You need to have a mechanism that can detect an issue automatically
  • Respond: The system needs to be able to take specific action when a problem is detected
  • Audit: The issue needs to be logged together will all relevant information

When you think about the response, try to think as simple as possible. The most important action that you need to do is to fail gracefully with a minimum impact on the rest of the system. On top of this, you can have more complex responses where you can switch to a secondary replica or persist the action to a temporary location until the service is up and running.

Common causes of transient faults can be:

  • Temporary unavailability
  • Network loss
  • Timeouts
  • Switch from one node to another

All these faults can be only temporary and basic mechanism like a retry mechanism can solve this issue. Even so, there are many on-premises systems that don’t have a retry policy when they communicate with storage or with an external service.

The challenge of a detecting mechanism for transient failures is to know if the failure lasts for a long period or is transient. This is why most retries mechanism includes a counter and different ways to calculate the waiting time between retries.
In most of the cases, client libraries are providing a built-in mechanism for retry policies. Let’s take as example Azure Blob Storage library that has multiple retry policies build-in. Developers can decide what policy they want to use. Remember that not for all errors a retry policy will solve the issue. For example, if you get a 401 Unauthorized, there is no sense to try to reconnect to the Azure Blob Storage. It is pretty clear from the error code that you have the right credentials or you don’t have access to that specific resource. The retry policy will not help in this case.

There are multiple strategies when using a retry mechanism from exponential back-off to random value for sleep time. Depending on your scenarios and what you want to achieve you will need to test different mechanism and identify the ideal values for retry time interval and the number of retries.

The most used retry mechanisms are using:

  • Immediate retry (can be dangerous)
  • Fix Interval
  • Incremental Interval
  • Exponential Interval
  • Random Interval

The most common mechanism is based on Exponential Interval, that it is supported by most of the libraries. If you have strict SLAs than you need to be careful with the time interval values that you decide to use. You might be forced to use a fixed interval combined to be able to meet a specific SLA.

When you're application has multiple layers be sure that you don’t have multiple retry mechanism that overlap and each retry policy will stop automatically. Testing the retry policy is also an important step that needs to be done especially when you don’t use a retry policy from the library SDK.
For complex systems, you need a mechanism that can detect and mark a system as down. For example, if you have a web application that is using Azure Redis Cache, you don’t want each client to try to access cache once it is down. The system shall be able to be aware of this and reject any other calls to the cache system as long as the service is down. For this scenarios, a Circuit Breaker can be used to avoid retries policies when are not necessary. Circuit Breaker is giving you the capability to monitor channel and block the communication when a failure is detected. In most of the implementations, some requests are allowed to be executed and are used to monitor the channel and mark the channel up again if the communication succeeds. 
There are many other mechanisms that can be used for self-healing. A part of them can be found below:

  • Retry-policy
  • Circuit Breaker
  • Bulkhead
  • Queues
  • Fail-over
  • Intermediate check-points
  • Leader Election
  • Block bad clients (actors)
  • Clients throttle 
  • Load Balancer

Before jumping to the next topic, I want to prepare a post that describes how you can combine multiple services that are available inside Azure to have a self-healing system.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too