Is it a good idea to queue API requests on a cloud function?

I am using Netlify cloud functions as a middleware for a particular API integration on my site.

Now, the issue is that this API has a rate limit of 2 calls/ second. This might be an issue when my site has high traffic and there are more than 2 users triggering the function endpoint every second, which ends up calling the API more than 2 times/ second.

How do I deal with this issue? I though about queueing the requests in can be a good idea. Has anyone ever implemented something of this sort on Netlify before? Are there any other ideas/ suggestions/ approaches that I should consider here?

Thank you so much!

2 calls per second sounds like a very low limit and this would not be usable in any useful production application. I’d suggest you to look for a different API or upgrade to some higher plan if available as that’s a better solution than trying to engineer a solution to this.

For example, even if you work out a solution, it could look something like:

  1. Create a database
  2. Queue all the requests in there
  3. Create a scheduled function or something that would read from that database and process the next 2 requests in line. However, cron jobs won’t get faster than a minute, so this would be too sow.