You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to build resilient HTTP apps using the Microsoft.Extensions.Http.Resilience NuGet package.
4
4
author: IEvangelist
5
5
ms.author: dapine
6
-
ms.date: 10/20/2023
6
+
ms.date: 07/01/2024
7
7
---
8
8
9
9
# Build resilient HTTP apps: Key development patterns
@@ -81,13 +81,26 @@ The preceding code adds the standard resilience handler to the <xref:System.Net.
81
81
82
82
The default configuration chains five resilience strategies in the following order (from the outermost to the innermost):
83
83
84
-
| Order | Strategy | Description |
85
-
|--:|--|--|
86
-
|**1**| Rate limiter | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. |
87
-
|**2**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including retry attempts, doesn't exceed the configured limit. |
88
-
|**3**| Retry | The retry pipeline retries the request in case the dependency is slow or returns a transient error. |
89
-
|**4**| Circuit breaker | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. |
90
-
|**5**| Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. |
84
+
| Order | Strategy | Description | Defaults |
85
+
|--:|--|--|--|
86
+
|**1**| Rate limiter | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | Queue: `0`<br>Permit: `1_000`|
87
+
|**2**| Total timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including retry attempts, doesn't exceed the configured limit. | Total timeout: 30s |
88
+
|**3**| Retry | The retry pipeline retries the request in case the dependency is slow or returns a transient error. | Max retries: `3`<br>Backoff: `Exponential`<br>Use jitter: `true`<br>Delay:2s |
89
+
|**4**| Circuit breaker | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | Failure ratio: 10%<br>Min throughput: `100`<br>Sampling duration: 30s<br>Break duration: 5s |
90
+
|**5**| Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Attempt timeout: 10s |
91
+
92
+
#### Retries and circuit breakers
93
+
94
+
The retry and circuit breaker strategies both handle a set of specific HTTP status codes and exceptions. Consider the following HTTP status codes:
95
+
96
+
- HTTP 500 and above (Server errors)
97
+
- HTTP 408 (Request timeout)
98
+
- HTTP 429 (Too many requests)
99
+
100
+
Additionally, these strategies handle the following exceptions:
101
+
102
+
-`HttpRequestException`
103
+
-`TimeoutRejectedException`
91
104
92
105
## Add standard hedging handler
93
106
@@ -108,13 +121,13 @@ The standard hedging uses a pool of circuit breakers to ensure that unhealthy en
108
121
109
122
The preceding code adds the standard hedging handler to the <xref:Microsoft.Extensions.DependencyInjection.IHttpClientBuilder>. The default configuration chains five resilience strategies in the following order (from the outermost to the innermost):
110
123
111
-
| Order | Strategy | Description |
112
-
|--:|--|--|
113
-
|**1**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including hedging attempts, doesn't exceed the configured limit. |
114
-
|**2**| Hedging | The hedging strategy executes the requests against multiple endpoints in case the dependency is slow or returns a transient error. Routing is options, by default it just hedges the URL provided by the original <xref:System.Net.Http.HttpRequestMessage>. |
115
-
|**3**| Rate limiter (per endpoint) | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. |
116
-
|**4**| Circuit breaker (per endpoint) | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. |
117
-
|**5**| Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. |
124
+
| Order | Strategy | Description | Defaults |
125
+
|--:|--|--|--|
126
+
|**1**| Total request timeout | The total request timeout pipeline applies an overall timeout to the execution, ensuring that the request, including hedging attempts, doesn't exceed the configured limit. | Total timeout: 30s |
127
+
|**2**| Hedging | The hedging strategy executes the requests against multiple endpoints in case the dependency is slow or returns a transient error. Routing is options, by default it just hedges the URL provided by the original <xref:System.Net.Http.HttpRequestMessage>. | Min attempts: `1`<br>Max attempts: `10`<br>Delay: 2s |
128
+
|**3**| Rate limiter (per endpoint) | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | Queue: `0`<br>Permit: `1_000`|
129
+
|**4**| Circuit breaker (per endpoint) | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | Failure ratio: 10%<br>Min throughput: `100`<br>Sampling duration: 30s<br>Break duration: 5s |
130
+
|**5**| Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Timeout: 10s |
0 commit comments