djangodjango-rest-frameworkrate-limiting

How to queue requests to Django backend server to fit API rate limit


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.


Solution

  • 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