This project implements fixed-window rate limiters using Redis to manage request limits for users based on their subscription type. It provides three variants with varying caching mechanisms:
- Vanilla Rate Limiter: No caching; ensures consistent data by always querying Redis.
- Periodic Pooling + RAM Caching Rate Limiter: Combines lazy caching with periodic synchronization from Redis.
- Subscription + RAM Caching Rate Limiter: Uses Redis Pub/Sub to proactively update local caches in real-time.
- The objective is to rate limit a service with one operational endpoint.
- User types can be one of the following:
normal_user,premium_user, oradmin. - Max allowed requests for user types are not changed frequently, resulting in reasonably low configuration load.
- Any user can make a minimum of 0 requests.
- The service is under reasonably high load, with multiple replicas of the server behind a load balancer.
- This necessitates the use of a centrally accessible database (Redis) for maintaining the
Request_countinstead of storing it as a Python dictionary in memory.
- This necessitates the use of a centrally accessible database (Redis) for maintaining the
-
User_Requestcount_map- Tracks the live number of requests received from each user.
- Each key (user ID) has an expiry of 1 minute.
-
User_Usertype_map- Maps each user ID to their corresponding user type (e.g.,
normal_user,premium_user,admin).
- Maps each user ID to their corresponding user type (e.g.,
-
Usertype_Maxnumrequests_map- Maps each user type to its respective maximum allowed requests.
- A dummy Flask-based HTTP server is implemented with one endpoint:
- Endpoint:
/submit_job
Decorated with aRate_limiter_checkfunction, which implements the rate limiter before executing the core logic.
- Endpoint:
- Rate limiting using a fixed-window approach.
- Redis-backed live request tracking with a flexible schema.
- Modular implementation of rate limiter variants:
- Vanilla Rate Limiter: No caching, strict consistency.
- Periodic Pooling + RAM Caching: Lazy caching with periodic syncs.
- Subscription + RAM Caching: Real-time updates using Redis Pub/Sub.