RateLimiter is portable and extensible module which controle request rate. It has the following features
- Dependency Injection with simple implementation (can be refactored with Guice)
- Implemented two rate limiting algorithm
- Token-based, supporting both memory and distributed (framework) implementation
- Counter-based with sliding window
- Extensible and Configurable modules
Install the prerequisites.
Compile and run unit test
$ mvn clean test
Run integration test
$ mvn failsafe:integration-test
Package generation and run all tests
$ mvn install
com.dguo.ratelimiter.RateLimiter
is the entry point of the module.
com.dguo.ratelimiter.config
Put the config manager implementation which is responsible for rate limit config for different client and request. In the current version, only the static config is implemented.
com.dguo.ratelimiter.strategy
Define the rate limiting strategy interface, and two popular strategies have been implemented. One is the TokenBased and the other is CounterBased.
com.dguo.ratelimiter.token.consumer
The memory-based token algorithm has been implemented.
Token-based rate limiting with active request mode is popular in distributed environments. For example, the token-consumer is running in multiple load-balancer servers; and the token-producer which is running on different server(s) is responsible for responding the token request from consumer, and maintaining the global token consistency. In current version, only the memory-based consumer has been implemented.
com.dguo.ratelimiter.counter
Only the memory-based sliding-window counter algorithm has been implemented.
bean.properties
is the file to define dependency injection.
com.dguo.ratelimiter.integration.RateLimiterIT
implements integration test cases both for TokenMemoryBasedStrategy and SlideWindowCounterStrategy.
- Guice usage
- DynamoDB && File config manager
- Token Agent (REST API or RPC)
- Token Producer which is running on distributed platform
- Data Persistence