Thanks, Jaromir for the reply. Yes. I did check the Bucket4j implementation. Couple of things I did notice is
- It uses a token bucket algorithm and refilling of the token is done during tryAndConsume(int) method
- I felt its more of client-side rate limiter. I am looking for a server-side rate limiter.
The design i am looking is in 2 ways:
1. Asynchronous - Where application pushes the event for rate-limiting server via kafka, consumer, which is a rate limiter server consumes the data and check if there is rate limit violation. If no violation, update the counter, if there is violation, add violation event in cache with specific ttl. Till the violation event present in cache, applications will throw 429 for client.
2. Synchronous - Where application calls the rate-limiting server, violation is derived and replied back to client with decision. This adds up latency and thats where i am concerned to use the efficient algorithm and distributed data structure. Because rate limiter server is central rate limiting solution for many applications.
Regards,
Pavan