What is the best order to apply multiple Polly policies?

3k views Asked by At

The order in which Polly policies are encapsulated change the final result. Which is the best order if I want to use the following policies? This is the best order I could think of: the retries should be submitted to the bulkhead limits, and the circuit breaking is a lower-level policy that follows the timeout policy. Makes sense?

services.AddHttpClient<IService, Service>()
                .AddPolicyHandler(PolicyConfig.RetryPolicy);     
                .AddPolicyHandler(PolicyConfig.BulkheadPolicy)
                .AddPolicyHandler(PolicyConfig.CircuitBreakingPolicy)
                .AddPolicyHandler(PolicyConfig.TimeoutPolicy)
1

There are 1 answers

0
silkfire On

The policies are applied in the order defined, i.e. the first policy is the outer one, all the way to the last one (the innermost one).

Relevant documentation:

https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory#what-order-are-multiple-policies-applied-in