Can anyone explain Bulkhead policy in polly
Can anyone explain Bulkhead policy in polly
I want to send API calls to an external API that only allows 10 calls per second. Therefore, I need my program to be limited to making only 10 HTTP calls per second. Additionally, if I encounter a 429 error (too many requests), I want to retry that call. I learned about the Bulkhead pattern from this article: https://medium.com/@ynskrn54/using-polly-and-the-bulkhead-pattern-in-net-f4a9639e2fcd, which helps in preventing overwhelming the external API.
I have written some code based on this pattern. My understanding is that this code will manage 10 calls at a time in a queue. For instance, if I have 30 HTTP calls to make, they will be queued and processed at a rate of 10 calls per second.
Is the below code serve my purpose
2 Replies
In this example, we allow up to 5 concurrent executions and an unlimited queue. Adjust these values based on your application’s requirements and resource constraints.
Your code will allow up to 10 concurrent executions and a limited queue to 1. So making 30 request at once, 10 will be executed, 1 is added to the queue and 19 will go to walhalla 😉
But Polly has such a rate-limiter build in
https://github.com/App-vNext/Polly#rate-limiter
GitHub
GitHub - App-vNext/Polly: Polly is a .NET resilience and transient-...
Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and ...