Hi, I am trying to using async to make multiple requests to the Jira REST API at the same time. But after a few requests I get error code 429 (Too many requests) due to rate limiting of the API. I would like some help in this case since I really need to make multiple API calls without the code crashing because of response 429
Getting a 429 means that you’re doing too many requests in a short time.
This is done in order to prevent abuse and to keep the server load under control: imagine if every app had unlimited access and tried to fetch as much data as possible, Atlassian’s server cost would skyrocket.
What you should do is limit the amount of concurrency, e.g. instead of making 20 calls at the same time make 3 at a time, that’s still better than fetching sequentially.
Moreover, when you get a 429 you also get information in the response headers about when you’ll be able to make further requests, check that header and act accordingly: don’t spam requests until one goes through or you may get even worse limits.
There are libraries and tools that can help you in most major languages, you can use
ExecutorService with a fixed thread pool in Java…
+1 to @PaoloCampanelli’s answer.
I could do that but from what I understand, the limit is not fixed and depends on several factors.
Thanks for the guide, this helps set the calls according to the Retry-After parameter
For everyone reading this thread, this point cannot be understated. The “cost-based rate limiting” is about a cost that is internal to Atlassian and is a complex and dynamic function of code and infrastructure – the limit as a number is practically opaque for apps. Hence, the only appropriate strategy available is “negotiation” where your app must react to per-request signals to speed up (typically governed by the critical path of the app itself) or slow down (based on the specification of rate limiting). You can’t solve this with a simple calculation of a fixed rate over time.