Rate Shield is a robust rate-limiting project designed for Node.js applications, utilizing the NestJS framework and Redis. It is built to protect APIs from excessive use and to prevent abuse, ensuring fair resource usage across all users.
- Rate Limiting: Enforces request limits per hour based on IP address for public routes and user tokens for private routes.
- Concurrency Handling: Efficiently handles multiple concurrent requests, ensuring stability and reliability even under high traffic.
- Scalable Architecture: Can work with multiple instances of the application, allowing for horizontal scaling.
- NestJS
- Redis
- TypeScript
Clone the repository
git clone https://github.com/thebozturk/rate-shield.git
Go to the project directory
cd rate-shield
Install dependencies
npm install
Run the application
npm start
Run unit tests
npm run test
Private Routes: Limits are enforced based on user tokens. If the limit is exceeded, the server responds with a 429 Too Many Requests status code and a message indicating when to try again. Public Routes: Limits are enforced based on IP addresses with similar response behavior as private routes.
Exceeding Rate Limit
{
"message": "Rate limit exceeded",
"error": "Too Many Requests",
"Try_Again_After": "5 minutes"
}