Skip to content

Rate limiter · 1 of 6

Step 1 · The pattern

Count per window, then forget

The limiter keeps one counter per client for the current window. Each request adds one. When the window ends, the counter goes back to zero. This batch job sends 8 per window, under its limit of 10.

  • user request
  • batch job
  • served

In short

Fixed vs sliding window: how it works and how it breaks

The simplest rate limit is a counter per client per clock window: ten requests per minute, and the counter goes back to zero when the minute ends. It is cheap and easy to explain, and it holds the average. The weakness is the reset. A client can spend a full allowance in the last moments of one window and another in the first moments of the next. Each window saw a legal count, yet the service received double the limit almost at once. A sliding window asks a different question: how many requests did this client make in the window length ending now? There is no boundary to straddle, so the second burst is refused. Keeping every timestamp gives an exact answer but costs memory, so real systems usually estimate it from two counters: the current window, plus a share of the previous one.

How this comes up in interviews

"Design a limit of 100 requests per minute per client. How do you count, and what is the worst case your service must absorb?"

Then they ask

  1. A client sends a full allowance on each side of the reset. What does the service see, and how do you prevent it?
  2. An exact sliding window keeps every timestamp. What does that cost, and what is the cheaper estimate?
  3. How can the two-counter estimate be wrong, and when is that error acceptable?

A strong answer covers

  • A fixed window keeps one counter per client per clock window: cheap, easy to explain, and it holds the average.
  • Its weakness is the reset: a burst on each side of the boundary lets double the limit through almost at once.
  • A sliding window counts the requests made in the window length ending now, so there is no boundary to straddle.
  • Keeping every timestamp is exact but costs memory, so real systems estimate from the current counter plus a share of the previous one.
  • If you keep a fixed window, size the service for double the limit.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last updated: Engineering write-up

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.