System Designsimulator

Rate limiter simulator

A rate limit like “10 requests per second” sounds precise, but each algorithm enforces it differently. Some let a burst through, some smooth traffic out, and one can let through twice the limit in a single second.

Counts requests in windows aligned to the clock and resets at each boundary. Cheap, but a burst either side of a boundary can pass twice the limit.

10 s: 60 allowed, 0 rejected
Over the limit

Fixed window let 20 requests through in a single 1 s window: 2× the limit of 10.

Rejected0%0 of 60 requests
0 ms2 s4 s6 s8 s10 s010Arrival time (grid lines are window boundaries)
Allowed (lower part)Rejected (upper part)
Why more than the limit got through

Requests just before and just after a window boundary count against different windows, so 20 reached the backend within one 1 s.

Limiter and traffic

The limit applies per window; buckets refill or drain at limit ÷ window.

Used by the token and leaky buckets only.

Pattern

Not used by the boundary pattern, which sends the limit just before and just after three window boundaries.

Change it to draw different random traffic.

Most in any 1 s202× the limit of 10
Arrived60Over 10 windows
Allowed60100%

What it shows

A limit like “10 requests per second” sounds precise, but each algorithm enforces it differently. Some let a burst through, some smooth traffic out, and one can let through twice the limit in a single second.

This simulator sends the same traffic through five algorithms: token bucket, leaky bucket, fixed window, sliding window log and sliding window counter. It counts what each allows and rejects, and the most requests that reach your backend in any one window.

How to read it

  • The chart stacks allowed requests (lower part) and rejected requests (upper part) by arrival time. Grid lines are window boundaries.
  • “Most in any window” slides a window-length span across the whole run, not just clock-aligned windows. Above the limit means your backend saw more than the limit.
  • Bucket size is the burst a token bucket allows, or the leaky bucket’s queue length. Window algorithms ignore it.
  • “Longest queue wait” appears for the leaky bucket only: the delay a queued request adds.
  • The leaky bucket here queues requests. Some texts describe one that rejects, which behaves like a token bucket.
  • The table runs every algorithm on the same traffic. Select a name to chart it.

Questions

Which rate limiting algorithm should I use?

Token bucket if you want to allow short bursts but cap the average rate. Leaky bucket if your backend needs a smooth, steady flow and callers can tolerate added delay. Sliding window log if you need an exact count and can afford to store a timestamp per request. Sliding window counter if you want close to exact with two counters per key. Fixed window if simplicity matters most and a doubled burst at window edges is acceptable.

How accurate is the sliding window counter?

It assumes requests in the previous window were spread evenly. Cloudflare, which uses this approach, reported that across 400 million requests only 0.003% were wrongly allowed or rate limited. Uneven traffic, such as the bursty pattern here, can push it a little over the limit.

Why does fixed window let through twice the limit?

Its counter resets at every window boundary. A full limit of requests just before a boundary and another just after fall into different windows, so both are allowed within a span much shorter than one window.

Does anyone use the token bucket in production?

Yes. Stripe’s engineering blog describes using the token bucket algorithm for its API rate limiters.

Learn it properly

Sources

Explore further

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.