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.
Fixed window let 20 requests through in a single 1 s window: 2× the limit of 10.
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.
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.
| Algorithm | Allowed | Rejected | Most in a window | Longest wait |
|---|---|---|---|---|
| 33 | 27 | 11 over | none | |
| 36 | 24 | 10 | 990 ms | |
| Shown | 60 | 0 | 20 over | none |
| 30 | 30 | 10 | none | |
| 33 | 27 | 11 over | none |
Pick an algorithm’s name to show it above.
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
- Visualizing algorithms for rate limitingInteractive post that animates fixed window, sliding window and token bucket limiters.
Last updated
More tools
All tools- estimatorBack-of-envelope estimatorTurn daily users into requests per second, storage and bandwidth, with the working shown.Open tool
- simulatorConsistent hashing simulatorA hash ring with virtual nodes: key spread per node, and how many keys move when the cluster changes.Open tool
- estimatorQueue latency estimatorWhy latency explodes as servers get busy: utilisation, waiting time and Little’s law.Open tool