|
1 | 1 | --- |
2 | | -title: Implementing custom HTTP call retries with exponential backoff |
3 | | -description: .NET Microservices Architecture for Containerized .NET Applications | Implementing custom HTTP call retries with exponential backoff |
| 2 | +title: Explore custom HTTP call retries with exponential backoff |
| 3 | +description: Learn how you could implement, from scratch, HTTP call retries with exponential backoff to handle possible HTTP failure scenarios. |
4 | 4 | author: CESARDELATORRE |
5 | 5 | ms.author: wiwagn |
6 | | -ms.date: 05/26/2017 |
| 6 | +ms.date: 06/08/2018 |
7 | 7 | --- |
8 | | -# Implementing custom HTTP call retries with exponential backoff |
| 8 | +# Explore custom HTTP call retries with exponential backoff |
9 | 9 |
|
10 | | -In order to create resilient microservices, you need to handle possible HTTP failure scenarios. For that purpose, you could create your own implementation of retries with exponential backoff. |
| 10 | +To create resilient microservices, you need to handle possible HTTP failure scenarios. One way of handling those failures, although not recommended, is to create your own implementation of retries with exponential backoff. |
11 | 11 |
|
12 | | -In addition to handling temporal resource unavailability, the exponential backoff also needs to take into account that the cloud provider might throttle availability of resources to prevent usage overload. For example, creating too many connection requests very quickly might be viewed as a Denial of Service ([DoS](https://en.wikipedia.org/wiki/Denial-of-service_attack)) attack by the cloud provider. As a result, you need to provide a mechanism to scale back connection requests when a capacity threshold has been encountered. |
| 12 | +**Important note:** This section shows you how you could create your own custom code to implement HTTP call retries. However, it is not recommended to do it by your own but to use more powerful and reliable while simpler to use mechanisms, such as `HttpClientFactory` with Polly, available since .NET Core 2.1. Those recommended approaches are explained in the next sections. |
13 | 13 |
|
14 | | -As an initial exploration, you could implement your own code with a utility class for exponential backoff as in [RetryWithExponentialBackoff.cs](https://gist.github.com/CESARDELATORRE/6d7f647b29e55fdc219ee1fd2babb260), plus code like the following (which is also available on a [GitHub repo](https://gist.github.com/CESARDELATORRE/d80c6423a1aebaffaf387469f5194f5b)). |
| 14 | +As an initial exploration, you could implement your own code with a utility class for exponential backoff as in [RetryWithExponentialBackoff.cs](https://gist.github.com/CESARDELATORRE/6d7f647b29e55fdc219ee1fd2babb260), plus code like the following (which is also available at this [GitHub repo](https://gist.github.com/CESARDELATORRE/d80c6423a1aebaffaf387469f5194f5b)). |
15 | 15 |
|
16 | 16 | ```csharp |
17 | 17 | public sealed class RetryWithExponentialBackoff |
@@ -107,9 +107,11 @@ public async Task<Catalog> GetCatalogItems(int page,int take, int? brand, int? t |
107 | 107 | } |
108 | 108 | ``` |
109 | 109 |
|
110 | | -However, this code is suitable only as a proof of concept. The next topic explains how to use more sophisticated and proven libraries. |
| 110 | +Remember that this code is suitable only as a proof of concept. |
| 111 | +The next sections explain how to use more sophisticated approaches while simpler, by using HttpClientFactory. |
| 112 | +HttpClientFactory is available since .NET Core 2.1, with proven resiliency libraries like Polly. |
111 | 113 |
|
112 | 114 |
|
113 | 115 | >[!div class="step-by-step"] |
114 | 116 | [Previous](implement-resilient-entity-framework-core-sql-connections.md) |
115 | | -[Next](implement-http-call-retries-exponential-backoff-polly.md) |
| 117 | +[Next](use-httpclientfactory-to-implement-resilient-http-requests.md) |
0 commit comments