-
Notifications
You must be signed in to change notification settings - Fork 6k
Research and add defaults to HTTP resilience content #41611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ title: "Build resilient HTTP apps: Key development patterns" | |
description: Learn how to build resilient HTTP apps using the Microsoft.Extensions.Http.Resilience NuGet package. | ||
author: IEvangelist | ||
ms.author: dapine | ||
ms.date: 10/20/2023 | ||
ms.date: 07/01/2024 | ||
--- | ||
|
||
# Build resilient HTTP apps: Key development patterns | ||
|
@@ -81,13 +81,26 @@ The preceding code adds the standard resilience handler to the <xref:System.Net. | |
|
||
The default configuration chains five resilience strategies in the following order (from the outermost to the innermost): | ||
|
||
| Order | Strategy | Description | | ||
|--:|--|--| | ||
| **1** | Rate limiter | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | | ||
| **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. | | ||
| **3** | Retry | The retry pipeline retries the request in case the dependency is slow or returns a transient error. | | ||
| **4** | Circuit breaker | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | | ||
| **5** | Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | | ||
| Order | Strategy | Description | Defaults | | ||
|--:|--|--|--| | ||
| **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` | | ||
| **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 | | ||
| **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 | | ||
| **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 | | ||
| **5** | Attempt timeout | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Attempt timeout: 10s | | ||
|
||
#### Retries and circuit breakers | ||
|
||
The retry and circuit breaker strategies both handle a set of specific HTTP status codes and exceptions. Consider the following HTTP status codes: | ||
|
||
- HTTP 500 and above (Server errors) | ||
- HTTP 408 (Request timeout) | ||
- HTTP 429 (Too many requests) | ||
|
||
Additionally, these strategies handle the following exceptions: | ||
|
||
- `HttpRequestException` | ||
- `TimeoutRejectedException` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do the same thing for hedging? Just add circuit breaker exception too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow. So, the Hedging handler employs what defaults? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hedging has different Maybe just note that status codes/exceptions are the same as compared to standard resilience, but hedging strategy also handles |
||
|
||
## Add standard hedging handler | ||
|
||
|
@@ -108,13 +121,13 @@ The standard hedging uses a pool of circuit breakers to ensure that unhealthy en | |
|
||
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): | ||
|
||
| Order | Strategy | Description | | ||
|--:|--|--| | ||
| **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. | | ||
| **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>. | | ||
| **3** | Rate limiter (per endpoint) | The rate limiter pipeline limits the maximum number of concurrent requests being sent to the dependency. | | ||
| **4** | Circuit breaker (per endpoint) | The circuit breaker blocks the execution if too many direct failures or timeouts are detected. | | ||
| **5** | Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | | ||
| Order | Strategy | Description | Defaults | | ||
|--:|--|--|--| | ||
| **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 | | ||
| **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 | | ||
| **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` | | ||
| **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 | | ||
| **5** | Attempt timeout (per endpoint) | The attempt timeout pipeline limits each request attempt duration and throws if it's exceeded. | Timeout: 10s | | ||
|
||
### Customize hedging handler route selection | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.