Home > Back-end >  How to queue requests to Django backend server to fit API rate limit
How to queue requests to Django backend server to fit API rate limit

Time:11-13

I have a web project which is based on some API from RapidAPI. This API has 10 requests/sec rate limit. All the requests to this API are processed by server side using Django with Rest framework library. Front-end is based on Vue. So this is kind of simple web app.

The problem is that I need to somehow queue all the requests from website users to not exceed rapidapi rate limit, because if I do - some pages wouldn't load some content because the api returns 429 error.

Usually it happens when some component needs to load data from 3 different api endpoints. Also this would relate to situation when we have for example 10 online users who are actively clicking on page components which needs to fetch some data so I want to find some way to resolve it.

CodePudding user response:

asynchronous workers:

a robust hard to digest: https://docs.celeryq.dev/en/stable/getting-started/introduction.html

a simpler but good: https://github.com/rq/rq

or the bare metal: https://docs.python.org/3/library/queue.html

CodePudding user response:

To expand on the suggestion from Franco Milanese, I suggest using a worker that is separate from your Django app. This will download the data separtely and save it somewhere that the Django app can access. Then your Django app can load the data from that cache when it serves any pages that need it.

  • Related