Distributed Rate Limiter with Hazelcast

770 views
Skip to first unread message

pura...@gmail.com

unread,
Jul 14, 2020, 5:20:13 AM7/14/20
to Hazelcast
Hello All,
I want to build a distributed rate limiting solution and want to use hazelcast for rate-limiting specifically sliding window algorithm. 
Any views/suggestions on using hazelcast distributed data structures to build a sliding window for rate limiting is highly appreciative.

Regards,
Pavan

Jaromir Hamala

unread,
Jul 14, 2020, 7:22:36 AM7/14/20
to Hazelcast
Hello Pavan,

the simplest solution is to use Hazelcast integration with the Bucket4j library. See: https://github.com/vladimir-bukhtoyarov/bucket4j/blob/master/doc-pages/hazelcast.md

Cheers,
Jaromir

PAVAN PURANIK

unread,
Jul 14, 2020, 1:50:16 PM7/14/20
to Hazelcast
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
Reply all
Reply to author
Forward
0 new messages