Try
↑ ↓ move↵ openesc close

Interview prep / Rate limiting algorithms

Junior · Rate limiting algorithms · System design interview question

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

Learn it by running it

The rate limiting algorithms lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms