Rate-Limiter (Singleton / Factory / Strategy Example)
This sample Java project demonstrates how to implement API Rate Limiting in a framework-agnostic way using classic design patterns:
- Singleton (for centralized configuration)
- Strategy (to allow different rate-limiting algorithms)
- Factory (to decide which strategy to use at runtime)
It includes:
- Fixed Window rate-limiter (FixedWindowRL)
- Sliding Window rate-limiter (SlidingWindowRL)
- A Servlet Filter example (RateLimitingFilter) to show how to integrate into a typical web environment
- A standalone demo class (MainDemo) for quick testing
Run the code from com.example.ratelimit.demo.MainDemo
- Factory
- Strategy
- Singleton
- SOILD