Rate Limiting Pattern #2973
Pull Request Template
What does this PR do?
This PR implements the Rate Limiting Design Pattern in Java using three different strategies:
- Token Bucket
- Fixed Window
- Adaptive Rate Limiter
It simulates concurrent client requests to multiple services (S3, DynamoDB, Lambda) and applies appropriate rate-limiting logic to manage request throughput, prevent system overload, and simulate elastic behavior under pressure.
PR Summary
This PR implements the Rate Limiting Design Pattern in Java using three different strategies: Token Bucket, Fixed Window, and Adaptive Rate Limiter. It simulates concurrent client requests to multiple services (S3, DynamoDB, Lambda) and applies appropriate rate-limiting logic to manage request throughput, prevent system overload, and simulate elastic behavior under pressure. The implementation includes comprehensive unit tests and diagrams.
Changes
| File | Summary |
|---|---|
pom.xml |
Updated the parent pom.xml to include the rate-limiting-pattern module and fixed spacing. |
rate-limiting-pattern/README.md |
Added a comprehensive README file explaining the rate limiting pattern, including diagrams, code examples, and real-world applications. |
rate-limiting-pattern/etc/AdaptiveRateLimiter.png |
New file: Added a flowchart diagram for the Adaptive Rate Limiter strategy. |
rate-limiting-pattern/etc/FixedWindowRateLimiter.png |
New file: Added a flowchart diagram for the Fixed Window Rate Limiter strategy. |
rate-limiting-pattern/etc/TokenBucketRateLimiter.png |
New file: Added a flowchart diagram for the Token Bucket Rate Limiter strategy. |
rate-limiting-pattern/etc/UMLClassDiagram.png |
New file: Added a UML class diagram illustrating the relationships between classes in the rate limiting pattern. |
rate-limiting-pattern/pom.xml |
Added a pom.xml file for the rate-limiting-pattern module, defining dependencies and build configurations. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/AdaptiveRateLimiter.java |
Implemented the AdaptiveRateLimiter class, which dynamically adjusts the rate limit based on system health. It uses a TokenBucketRateLimiter internally and periodically adjusts the limit based on success or failure of requests. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/App.java |
Created a main application class to demonstrate the usage of the different rate limiter strategies with simulated concurrent client requests to multiple services. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/FindCustomerRequest.java |
Created a FindCustomerRequest class that implements RateLimitOperation to represent a rate-limited customer lookup operation. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/FixedWindowRateLimiter.java |
Implemented the FixedWindowRateLimiter class, which uses a simple counter within a fixed time window to limit the number of requests. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/RateLimitException.java |
New file: Created a base exception class for rate limiting errors. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/RateLimitOperation.java |
New file: Created an interface RateLimitOperation to represent a business operation that needs rate limiting. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/RateLimiter.java |
New file: Created an interface RateLimiter for different rate limiting strategies. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/ServiceUnavailableException.java |
New file: Created an exception class for when a service is temporarily unavailable. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/ThrottlingException.java |
New file: Created an exception class for when AWS-style throttling occurs. |
rate-limiting-pattern/src/main/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiter.java |
Implemented the TokenBucketRateLimiter class, which uses a token bucket algorithm to control the rate of requests. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/AdaptiveRateLimiterTest.java |
New file: Added unit tests for the AdaptiveRateLimiter class, verifying its behavior under different scenarios. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/AppTest.java |
New file: Added unit tests for the App class, covering different scenarios like successful requests, throttling, and service unavailability. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/AppTestUtils.java |
New file: Added utility methods for testing the App class. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/ConcurrencyTests.java |
New file: Added concurrency tests to verify the behavior of the rate limiters under concurrent requests. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/ExceptionTests.java |
New file: Added unit tests for the custom exception classes, verifying their functionality. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/FindCustomerRequestTest.java |
New file: Added unit tests for the FindCustomerRequest class, verifying its execution under different conditions. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/FixedWindowRateLimiterTest.java |
New file: Added unit tests for the FixedWindowRateLimiter class, verifying its behavior under different scenarios. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/RateLimitOperationTest.java |
New file: Added an interface for testing RateLimitOperation implementations. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/RateLimiterTest.java |
New file: Added an abstract class for testing RateLimiter implementations. |
rate-limiting-pattern/src/test/java/com/iluwatar/rate/limiting/pattern/TokenBucketRateLimiterTest.java |
New file: Added unit tests for the TokenBucketRateLimiter class, verifying its behavior under different scenarios. |
autogenerated by presubmit.ai
Quality Gate passed
Issues
13 New issues
0 Accepted issues
Measures
0 Security Hotspots
91.9% Coverage on New Code
0.0% Duplication on New Code
This PR is stale because it has been open 60 days with no activity.