2 Comments

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

I think that your implementation of sliding window counter is not correct because of your calculation based on the following:

Window Transition Logic:

The logic moves to a new window if the elapsed time (timePassedInWindow) exceeds the windowSizeInSeconds.

If the elapsed time is much greater than the window size (size 15 seconds and elapsed time e.g.100 seconds), it effectively considers the last "previous window" as still valid. The previousWindowCount is updated with the currentWindowCount regardless of the gap.

Weighted Count:

The calculation combines a weighted count of the previous window and the current window. This includes the current window’s elapsed time and the proportion of the previous window that overlaps with the sliding window.

Handling Long Gaps:

When long gaps occur e.g. above 100 seconds between last and current request with 15 seconds window, the previous window’s count remains part of the calculation, even if its relevance has expired due to the large time gap.

Expand full comment