Skip to content

Commit 1b772c4

Browse files
CESARDELATORREBillWagner
authored andcommitted
Updates Microservice book on Resilient communication features with HttpClientFactory in .NET Core 2.1 with Polly (#5900)
* Uodates HttpClientFactory netcore2.1 with Polly Retries & Circuit-Breaks * Uodates HttpClientFactory netcore2.1 with Polly Retries & Circuit-Breaks * Updates based on Bill Wagner's feedback * Updates based on Feedback from Maira and Bill
1 parent 1360731 commit 1b772c4

11 files changed

+313
-316
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
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.
44
author: CESARDELATORRE
55
ms.author: wiwagn
6-
ms.date: 05/26/2017
6+
ms.date: 06/08/2018
77
---
8-
# Implementing custom HTTP call retries with exponential backoff
8+
# Explore custom HTTP call retries with exponential backoff
99

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.
1111

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.
1313

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)).
1515

1616
```csharp
1717
public sealed class RetryWithExponentialBackoff
@@ -107,9 +107,11 @@ public async Task<Catalog> GetCatalogItems(int page,int take, int? brand, int? t
107107
}
108108
```
109109

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.
111113

112114

113115
>[!div class="step-by-step"]
114116
[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)

docs/standard/microservices-architecture/implement-resilient-applications/handle-partial-failure.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: Handling partial failure
33
description: .NET Microservices Architecture for Containerized .NET Applications | Handling partial failure
44
author: CESARDELATORRE
55
ms.author: wiwagn
6-
ms.date: 05/26/2017
6+
ms.date: 06/08/2018
77
---
88
# Handling partial failure
99

10-
In distributed systems like microservices-based applications, there is an ever-present risk of partial failure. For instance, a single microservice/container can fail or might not be available to respond for a short time, or a single VM or server can crash. Since clients and services are separate processes, a service might not be able to respond in a timely way to a client’s request. The service might be overloaded and responding extremely slowly to requests, or might simply not be accessible for a short time because of network issues.
10+
In distributed systems like microservices-based applications, there is an ever-present risk of partial failure. For instance, a single microservice/container can fail or might not be available to respond for a short time, or a single VM or server can crash. Since clients and services are separate processes, a service might not be able to respond in a timely way to a client’s request. The service might be overloaded and responding extremely slowly to requests or might simply not be accessible for a short time because of network issues.
1111

1212
For example, consider the Order details page from the eShopOnContainers sample application. If the ordering microservice is unresponsive when the user tries to submit an order, a bad implementation of the client process (the MVC web application)—for example, if the client code were to use synchronous RPCs with no timeout—would block threads indefinitely waiting for a response. In addition to creating a bad user experience, every unresponsive wait consumes or blocks a thread, and threads are extremely valuable in highly scalable applications. If there are many blocked threads, eventually the application’s runtime can run out of threads. In that case, the application can become globally unresponsive instead of just partially unresponsive, as show in Figure 10-1.
1313

@@ -21,15 +21,15 @@ In a large microservices-based application, any partial failure can be amplified
2121

2222
**Figure 10-2**. The impact of having an incorrect design featuring long chains of HTTP requests
2323

24-
Intermittent failure is virtually guaranteed in a distributed and cloud based system, even if every dependency itself has excellent availability. This should be a fact you need to consider.
24+
Intermittent failure is guaranteed in a distributed and cloud-based system, even if every dependency itself has excellent availability. It is fact you need to consider.
2525

2626
If you do not design and implement techniques to ensure fault tolerance, even small downtimes can be amplified. As an example, 50 dependencies each with 99.99% of availability would result in several hours of downtime each month because of this ripple effect. When a microservice dependency fails while handling a high volume of requests, that failure can quickly saturate all available request threads in each service and crash the whole application.
2727

2828
![](./media/image3.png)
2929

3030
**Figure 10-3**. Partial failure amplified by microservices with long chains of synchronous HTTP calls
3131

32-
To minimize this problem, in the section "*Asynchronous microservice integration enforce microservice’s autonomy*” (in the architecture chapter), we encouraged you to use asynchronous communication across the internal microservices. We briefly explain more in the next section.
32+
To minimize this problem, in the section "*Asynchronous microservice integration enforce microservice’s autonomy*” (in the architecture chapter), this guidance encourages you to use asynchronous communication across the internal microservices.
3333

3434
In addition, it is essential that you design your microservices and client applications to handle partial failures—that is, to build resilient microservices and client applications.
3535

0 commit comments

Comments
 (0)