Skip to content

About

Implementation of Rate Limiter(Leaky Bucket) based on Redis cache engine.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

LeakyBucket RateLimiter using Redis

A Rate Limiter controls and restricts the rate at which requests can access an object or resource. This limit is typically measured in units such as Requests Per Second (RPS) or Requests Per Minute (RPM). The primary purpose of using a Rate Limiter is to ensure resources remain available and to prevent Denial of Service (DoS) attacks. One popular algorithm for implementing Rate Limiting is the Leaky Bucket algorithm. In this repository, the Leaky Bucket algorithm is implemented using the Redis cache engine.

  • Learn more about leaky bucket here.

  • For more details about this implementation read my blog post here.

Circuit Breaker:

As an example, a simple Circuit Breaker has been implemented using the Leaky Bucket Rate Limiter. To understand how a Circuit Breaker works, read Martin Fowler's article here.

Examples:

There are two examples: one demonstrates how to use a rate limiter to restrict the number of password recovery attempts for an email, and the other shows how to implement a circuit breaker in an alarming system to prevent notification flooding. Check examples.py.

Activate Env

uv sync

--> UV installation guide

Linting with Ruff

ruff format --check
ruff check

TODO list:

  • Implementation of async version
  • Implementation of other methods of rate limiting

About

Implementation of Rate Limiter(Leaky Bucket) based on Redis cache engine.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages