Hodor is a learner project designed to explore and implement distributed rate limiting. It serves as a practical example for understanding the concepts and challenges involved in building scalable and efficient rate-limiting systems.
In modern systems, APIs need to be scaled automatically. Multiple instances of API servers can run in multiple nodes, and enforcing global ratelimiting rules on autoscaling APIs can be an issue.
Few problems we try to solve in hodor :-
- Race conditions 1.1 Maintaining low latency while employing synchronization mechanisms
- Thundering herd
- Set rate limiting for FastAPI endpoints (decorators)
- Define strategy, limits
- Accurate rate limiting with autoscaling
- Fall back mechanisms during high traffic
api/
main.py # Entry point for example API
__init__.py # Package initialization
hodor/
config.py # Configuration management
decision.py # Core rate-limiting algorithms and decision engine
utils.py # Utility functions to interact with tools and third party services
wrappers.py # Wrappers for integrations with APIs
docker-compose.yaml # Spin up API, redis and other services in containers (Simulation of an actual production system and will be used to test autoscaling setups later)
test/ # Test cases and scripts
- Python 3.8+
- Docker and Docker Compose
-
Clone the repository:
git clone <repository-url> cd hodor
-
Create and activate a virtual environment:
python3 -m venv env source env/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
(Optional) Build and run the Docker containers:
docker-compose up --build
- Start the application:
python api/main.py
- Access the frontend at
http://localhost:8000(if applicable).
- Implement rate limiter library
- Distributed ID for users per API endpoint
- Race condition
- test by spinning up multiple API instances
- low latency solution
- Thundering herd problem
- fall back mechanisms
Contributions are welcome! Feel free to open issues or submit pull requests to improve the project.
This project is licensed under the MIT License. See the LICENSE file for details.