A Java simulation of API rate limiting that tracks user requests and blocks users after they exceed a predefined limit.
Each incoming request is associated with a user.
- If the user has not reached the request limit, the request is allowed.
- If the user has already reached the limit, the request is blocked.
- Request counts are tracked separately for each user.
- Tracks requests per user
- Enforces a maximum request limit
- Blocks requests that exceed the limit
- Displays request statistics
- Console-based simulation
This project uses JUnit 5 and Maven for unit testing.
- Allows a new user's first request
- Allows requests up to the configured limit
- Blocks requests after exceeding the limit
- Maintains independent request counts for different users
- Java Collections
- JUnit 5
- Unit Testing
- Maven
- HashMap
- Object-Oriented Programming
Rate limiting is a common technique used by APIs and web services to control traffic and prevent abuse.
This project was built to explore how backend systems enforce request limits using in-memory data structures. It demonstrates per-user request tracking, simple business logic, and unit testing with JUnit 5.
- Clone the repository:
git clone https://github.com/JavaLabs-io/RateLimiter.git
- Navigate to the project directory:
cd RateLimiter- Run the unit tests:
mvn test- Run the application by opening
RateLimiter.javain your IDE (such as VS Code, Eclipse, or IntelliJ IDEA) and executing themain()method.
