This project features:
- multiple rate limiting strategies
- leaderboard of user's scores
Built with in memory database Redis
Selectable at startup via rate-limiter.strategy
Two algorithms are implemented fixed window and sliding window log. Each with a non-atomic and an atomic (Lua script-based) version, to compare a naive multi-command approach against one that guarantees atomicity via Redis scripting.
One key per client with window size set as expiration. Low memory usage but possible 2x bursts at the boundaries with technique below
- Fire one request that will set expiration time.
- Near end of expiration time fire maximum amount of requests.
- Key expires at boundary.
- Fire max amount of requests again.
Each request timestamp is stored, and expired entries are pruned from the log on every request. More memory and compute intensive than fixed window, but provides exact rate limiting with no boundary bursts. Well suited for sensitive APIs and audit-critical endpoints.