Describe the fixed window counter. What is its main weakness?
Sketch your own answer first, then compare it with the one below.
A strong answer
It keeps a count and the start of the current window, for example one minute. Each admitted request adds one. When the clock passes the window edge, the count goes back to zero. A request is rejected if the count already equals the limit.
It is the cheapest limiter. It needs two numbers per caller, one increment per request, and no cleanup beyond the reset.
The weakness is the edge. The count forgets everything at the boundary. A caller that sends a full limit just before the edge and another full limit just after it gets twice the limit through in a very short time, and neither window was ever over. The same thing happens naturally when many clients all act at the top of a clock minute.
The worst case is twice the limit in any span the length of a window. There are two usual fixes: a sliding window, which needs more state, or a token bucket, which caps a burst at the bucket size plus what refills.
Sources
- Betsy Beyer, Chris Jones, Jennifer Petoff, Niall Richard Murphy (2016). Site Reliability Engineering, chapter 21, Handling Overload.