Discussion about this post

User's avatar
Yash's avatar

Nice post!!

Should the leaky bucket implementation should have timer-interrupt based implementation to leak the requests to be processed accurately? In current implementation it leaks at every new request, if the time gap b/w requests is huge that would lead to starvation of requests to be processed.

Expand full comment
Adarsh's avatar

For token bucket alog especially java logic the bucket is getting filled according to milliseconds, but i have doubt for rate limiting, doesn't we have to set it at the end of the seconds?

If yes we are setting at the end of the second then this algorithm will fail when there are multiple requests and if the bucket didn't have enough tokens it should reject the request as there are no enough tokens and if time has elapsed it should refill the bucket. But in given code as we are filling the bucket each time services get requests even though it didn't have enough tokens.

we have to add below condition in refill function -

if (elapsedSecondFromLastRefill <= 0) {

System.out.println("No refill needed, elapsed seconds: " + elapsedSecondFromLastRefill);

return;

}

correct me if I am wrong?

Expand full comment
1 more comment...

No posts