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
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:
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:
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:
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.
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
Post a Comment