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 atFixed windowSliding log
8yesyes
9yesyes
10yes: a new slot starts at 10no: 8 and 9 still count
11yesno

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.