18/32
Part 4 of 6 · Deques and rate limitsLearn and do
A sliding window doesn't restart on round numbers
Take four requests at 8, 9, 10 and 11, with a limit of 2 per 10 seconds. A counter that resets every 10 seconds and the sliding log answer differently:
| Request at | Fixed window | Sliding log |
|---|---|---|
| 8 | yes | yes |
| 9 | yes | yes |
| 10 | yes: a new slot starts at 10 | no: 8 and 9 still count |
| 11 | yes | no |
Write fixed_window, the counter that resets on the clock, and run it on the requests at 8, 9, 10 and 11 from the table.