Skip to content

Commit 2b671e8

Browse files
authored
Researched and add defaults to HTTP resilience content (#41611)
1 parent f400b6a commit 2b671e8

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

docs/core/resilience/http-resilience.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Build resilient HTTP apps: Key development patterns"
33
description: Learn how to build resilient HTTP apps using the Microsoft.Extensions.Http.Resilience NuGet package.
44
author: IEvangelist
55
ms.author: dapine
6-
ms.date: 10/20/2023
6+
ms.date: 07/01/2024
77
---
88

99
# Build resilient HTTP apps: Key development patterns
@@ -81,13 +81,26 @@ The preceding code adds the standard resilience handler to the <xref:System.Net.
8181

8282
The default configuration chains five resilience strategies in the following order (from the outermost to the innermost):
8383

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`
91104

92105
## Add standard hedging handler
93106

@@ -108,13 +121,13 @@ The standard hedging uses a pool of circuit breakers to ensure that unhealthy en
108121
109122
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):
110123

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 |
118131

119132
### Customize hedging handler route selection
120133

0 commit comments

Comments
 (0)