How to build a Rate Limiter using Redis

My Image

Rate limiting is a mechanism that many developers may have to deal with at some point in their life. It’s useful for a variety of purposes like sharing access to limited resources or limiting the number of requests made to an API endpoint and responding with a 429 status code. In this tutorial, we will see how to implement Rate Limiting using various programming languages:

Using Python#

Step 1. Pre-requisite#

  • Python
  • Docker
  • Docker Compose

Step 2. Clone the repository#

git clone

Step 3. Run docker compose or install redis manually#

docker network create global
docker-compose up -d --build

If you install redis manually open django-backend/configuration folder and copy .env.example to create .env. And provide the values for environment variables

- REDIS_HOST: Redis server host
- REDIS_PORT: Redis server port
- REDIS_DB: Redis server db index
- REDIS_PASSWORD: Redis server password

Step 4. Setup and run#

Install python, pip and venv (on mac:

Use python version: 3.8

python3 -m venv venv
source ./venv/bin/activate
pip3 install -r requirements.txt
python3 collectstatic
python3 runserver

Step 5. Accessing the rate limiting app

Rate Limiting