This challenge corresponds to the 27th part of the Coding Challenges series by John Crickett https://codingchallenges.fyi/challenges/challenge-rate-limiter.
This is a Node.js implementation of the following Rate limiter algorithms:
- token bucket
- fixed window counter
- sliding window log
- sliding window counter (with Redis support)
- Make sure to enable the support for RedisJSON by either using a Redis Stack or by manually adding the module.
All the algorithms are present in algorithms/ directory. They are very well documented with self explanatory code.
Note: All the algorithms support rate limiting based on the client's IP address.
You can use the ts-node
tool to run the NATS server as follows:
npx ts-node <path/to/index.ts> <algorithm>
Possible values for the algorithm are:
token-bucket
fixed-window-counter
sliding-window-log
sliding-window-counter
redis-sliding-window-counter
The default configurations are present in index.ts
for the the command line version of the Rate limiter tool.
You can also use the createRateLimiterServer
function defined in server.ts
in your code to get total control over the configurations.
To run the tests for the Rate Limiter, go to the root directory of this repository and run the following command:
npm test src/27/
- Add command line support for rate limiter args.
- Add Global rate limiting constraints with all algorithms.