I’m working on a web application that needs to send multiple requests to third party API, which have strict rate limits/per sec. When exceeding these limits, I receive a 429 Too Many Requests error, causing some requests to fail.
The challenge is that users expect immediate results in the web application. Since we don't have user authentication (its application requirement), it’s difficult to associate background jobs with specific users.
Making multiple API requests is a critical part of my application functionality, so I need a way to queue these requests while respecting rate limits. Using the sleep
method isn't good because it would block the Puma server and affect other requests.