educative.io

Rate limiter Algorithm | Fixed Window Counter Algorithm

How this could be a advantage in case of Fixed window counter algorithm? This also discards the requests once the counter has reached its limit.

  • As compared to token bucket-style algorithms (that discard the new requests if there aren’t enough tokens), this algorithm services the new requests.

Hi Vaibhav Arya,

You are right that the advantage you mentioned might not be an absolute advantage, but for some use-cases it is a preferable behavior. Both token-bucket style algorithms and fixed window counter algorithms discard incoming requests when their respective limits are reached. However, there’s a subtle distinction between these two strategies. Token-bucket style algorithms reject new requests and process older ones from the queue. Conversely, the fixed-window counter algorithm prioritizes new requests and discards older ones. To illustrate further, consider these two examples:

  1. Imagine an online game where we’re queuing character positions. Here, the latest position holds more importance, and discarding older positions is acceptable. For scenarios like this, the fixed-window counter algorithm is a suitable choice.

  2. Now, let’s think about sharing a recipe over WhatsApp. Each step in the recipe relies on the others, and omitting even one step could ruin the dish. Consequently, considering all the previous steps sent in various messages is crucial. In such cases, the token-bucket style algorithm, which serves older requests first, is more fitting.

While these examples may not be perfect, they clarify and help address any uncertainties.

I hope this will help.
Happy learning!

3 Likes

Hey @Bismillah_Jan!

Token-bucket style algorithms reject new requests and process older ones from the queue.

Do token-bucket style algorithms use a queue? Re-reading the section, I don’t see the word “queue”, but rather a flow diagram from “no sufficient tokens available” to “drop request”.

Hi Isaac Haseley,

Token-bucket algorithms manage network traffic and request handling by using tokens as a form of currency for request processing. When a new request comes in, it is only processed if there are sufficient tokens in the bucket, with each request consuming a predetermined number of tokens. If not enough tokens are available, the request might either be queued for later processing or rejected outright, depending on the system’s configuration and the implementation of the algorithm. This mechanism ensures that the system prioritizes older requests that are already in the queue (If the system’s configuration is to store requests in a queue) by processing them as tokens become available while potentially rejecting newer requests when the bucket lacks enough tokens, effectively controlling the flow of requests and maintaining system stability by preventing overload.

I hope this helps.
Happy learning!

Hey @Bismillah_Jan!

Thanks so much for the explanation! It may help to edit the diagram from “drop request” to something like “drop or queue request”.


Course: Grokking Modern System Design Interview for Engineers & Managers - Learn Interactively
Lesson: Rate Limiter Algorithms - Grokking Modern System Design Interview for Engineers & Managers