Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Fixed window counter algorithm

Sumit Rawal answered on May 21, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Sliding window counter algorithm

  • Fixed window counter algorithm

    0

    Fixed window counter algorithm works as follows:

    The algorithm divides the timeline into fix-sized time windows and assign a counter for each window.

    Each request increments the counter by one.

    Once the counter reaches the pre-defined threshold, new requests are dropped until a new time window starts.

    Let us use a concrete example to see how it works. In Figure 8, the time unit is 1 second and the system allows a maximum of 3 requests per second. In each second window, if more than 3 requests are received, extra requests are dropped as shown in Figure 8.

    Figure 8

    Figure 8

    A major problem with this algorithm is that a burst of traffic at the edges of time windows could cause more requests than allowed quota to go through. Consider the following case:

    Figure 9

    Figure 9

    In Figure 9, the system allows a maximum of 5 requests per minute, and the available quota resets at the human-friendly round minute. As seen, there are five requests between 2:00:00 and 2:01:00 and five more requests between 2:01:00 and 2:02:00. For the one-minute window between 2:00:30 and 2:01:30, 10 requests go through. That is twice as many as allowed requests.

    Pros:

    Memory efficient.

    Easy to understand.

    Resetting available quota at the end of a unit time window fits certain use cases.

    Cons:

    Spike in traffic at the edges of a window could cause more requests than the allowed quota to go through.  

    Popularity 1/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 21 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.