The limiter keeps just two numbers per key: how many requests it let through in the current fixed window, and in the previous one. To estimate the last W seconds it adds the current count to the part of the previous count that the rolling window still covers, and lets a request through while that estimate is under the limit. Below, an attacker joins two ordinary users: watch who is refused, and see where the estimate is right and where it is not.
Each dot stands for 579 real requests. Time is not scaled. The busiest stretch counts what really got through in any 5 seconds in a row, so it shows when the estimate is wrong.
Busiest hour vs the daily average. The book's estimate uses 2x.
Real limits often use a minute or an hour; the animation stays short so you can watch the window slide.
1. Average requests per second
2. Peak requests per second
3. Allowed rate r
4. Limit in any window L
5. What is arriving right now
6. Memory for the counter
Doubling DAU doubles the traffic, and because r and L are sized from that same traffic, it doubles them too. Every ratio stays the same, so the counter behaves identically and only the number each dot stands for changes. Unlike the sliding log, the memory does not change at all: it is two numbers either way.
Steps 1 and 2 are the estimation method from the back-of-the-envelope chapter of Alex Xu's System Design Interview, Vol. 1, including its 2x peak. Its rate limiter chapter describes the sliding window counter as the current window's count plus the previous window's count weighted by their overlap, and cites Cloudflare's measurements below. Steps 3 to 6 join the two, written here. The "nearly 2L" case follows from the formula: a full limit at the end of a quiet window is counted as if spread across it, so it is discounted while it is still inside the last W seconds.
Two engineering posts from 2017: one measures how accurate the estimate is, the other builds a variant of it.
GET, SET and INCR were available, keeping "only two numbers per counter". Its example: a limit of 50 per minute, 42 requests in the previous minute and 18 in the current one, 15 seconds in, gives 42 x 0.75 + 18 = 49.5. The post says the method "assumes a constant rate of requests during the previous sampling period", and reports that across 400 million requests from 270,000 sources, 0.003% were wrongly allowed or rate limited.Both are first-hand accounts from the companies' engineering blogs (primary sources). Cloudflare's post was published in June 2017; Figma's is by Nikrad Mahdi, April 2017. Quoted phrases are short attributed quotations; everything else is described in our words.