In this lesson · topic 4 of 7
Topic 4
What each limiter admits at the edge
6 min read
The numbers below come from the simulator with a fixed seed, and a test pins each one. Hover a value to see its setup. The limit is 20 per window of 20 ticks, and the token bucket and leaky bucket hold 20.
The window edge
With a burst of 20 on either side of an edge, this is the most each algorithm admitted in any 20 ticks in a row:
| Algorithm | Worst 20 ticks |
|---|---|
| Fixed window | 40measured |
| Sliding window log | 20measured |
| Sliding window counter | 20measured |
| Token bucket | 21measured |
| Leaky bucket | 20measured |
The fixed window admits twice the limit. That is its worst case, not an average. It happens when traffic is aimed at the edge, or when many clients retry at the top of a clock minute. The sliding log is never above the limit, by construction. The token bucket got one request over here because the first burst emptied it and only one tick of refill had arrived before the second. That is not its worst case. A bucket that has sat idle is full, and in any span it can give out its size plus what it refills during the span. With a bucket of 20 and a refill of one a tick, that is up to 40 in 20 ticks. The leaky bucket cannot exceed the drain rate at all.
Exact is not the same as kind
In steady traffic that averages 0.8 of the limit, random clumps still push some windows over. A strict limiter rejects those requests. The sliding log rejected 9%measured of the arrivals and the fixed window 3%measured. The token bucket rejected 0%measured, because its spare tokens absorb the clumps.
If your callers are well behaved, a strict limit punishes ordinary randomness. If you need a hard cap, for example a paid quota or a protected resource, strictness is what you want. Choose by what the limit is for.
Burst tolerance is a setting
For bursty traffic at the limit, a token bucket of 20 rejected 21%measured of the requests. With a bucket of 4 it rejected 71%measured. The refill rate was the same. A bucket holds a burst only if it is big enough to hold it. Set the rate from what the service can sustain and the bucket from the largest burst you are willing to take at once.
The leaky bucket takes the same bursts without a spike downstream, and the price is delay. In the lab, bursty traffic at 0.7 of the limit waited a mean of 9.1 ticksmeasured in its queue. That is fine for a background job and wrong for an interactive request.
Memory per caller
Peak state per caller, counted in stored values, with a limit of 60 per window and traffic at 1.5 times the limit:
| Algorithm | Values stored |
|---|---|
| Fixed window | 2measured |
| Sliding window counter | 3measured |
| Token bucket | 2measured |
| Sliding window log | 60measured |
| Leaky bucket | 60measured |
The log and the queue grow with the limit. The others do not. Multiply by the number of callers you track, which for a public API can be every address that reaches it, and the log becomes a real cost. It also costs work: every decision trims and scans a list.
Rejecting well
Rejection is part of the design. A limiter that says only “no” invites a retry loop. The standard answer is HTTP 429, Too Many Requests, usually with a Retry-After header that says when to come back. The next lesson looks at that signal and at what happens when the limit is the server’s own capacity.