A transient failure is a temporary problem, such as a network interruption, timeout, or temporarily unavailable remote service, that may succeed when the operation is retried. HTTP clients can handle these failures automatically so application code receives a successful result when possible. section 33.3 section 33.5
Handle transient HTTP failures by:
- Adding the Microsoft.Extensions.Http.Polly package. section 33.3
- Registering a named or typed HttpClient with AddTransientHttpErrorPolicy(). section 33.3 section 33.5
- Choosing a retry policy and delays, while retrying only requests that are safe to repeat. section 33.3 section 33.5
- Considering alternatives such as exponential backoff, circuit breakers, or failing quickly when retries are unlikely to help. section 33.3 section 33.5
Retrying a typed client request
builder.Services.AddHttpClient<ExchangeRatesClient>().AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1) })); This policy retries three times after connection errors, server errors, or timeout responses, without requiring the caller to implement retry logic. section 33.5

