Rate Limiter Simulator — Token Bucket vs Sliding Window
- This tool runs entirely in your browser. Nothing you enter or upload is sent to a server.
Traffic
Token bucket
A bucket of tokens refills at a steady rate and each request spends one, so short bursts pass while the long-run rate stays capped.
Fixed window
Counts requests in fixed slots of the window length and starts from zero at each boundary, which lets two full bursts through back to back.
Sliding log
Remembers the timestamp of every recent request and allows a new one only while fewer than the limit fall inside the trailing window.
Sliding counter
Weights the previous slot’s count by how much of it still overlaps the trailing window and adds the current slot: a cheap approximation of the log.
About this tool
A rate limiter decides, for each request, whether a client has used up its allowance, and it is one of the most common system design interview questions because the four standard algorithms make different trade-offs that are easy to describe and hard to picture. This simulator runs token bucket, fixed window, sliding log and sliding counter side by side on exactly the same stream of requests, so the differences stop being theoretical. Set a limit such as 10 requests per 5 seconds, let steady traffic flow, press Send burst to fire 15 requests at once, and watch each lane accept or deny them.
The token bucket holds up to *limit* tokens and refills them continuously; a request spends one. It allows a full-size burst at any moment, then smooths traffic to the refill rate, which is why it is the default in most API gateways. The fixed window counts requests in aligned windows and resets the count at each boundary. It is the cheapest to implement but has a well-known flaw: a client can send a full allowance at the end of one window and another at the start of the next, so twice the limit gets through in a short span. The simulator shows this if you send a burst just before a boundary.
The sliding log records the timestamp of every accepted request and counts how many fall inside the trailing window. It is exact, never allows more than the limit in any window, and costs memory proportional to the limit for every client, which is fine for a few hundred requests per minute and expensive for millions of clients. The sliding counter approximates the log with two counters, weighting the previous window by how much of it still overlaps the trailing window. It uses constant memory and is within a few percent of the exact answer, which is why Cloudflare and others use it at the edge.
Each lane shows a meter (tokens used, or requests counted against the limit), running totals of allowed and denied requests, and a timeline of the last ten seconds with every request marked. Reset clears everything and starts the clock again. Everything runs in your browser; there is no server and no real traffic.
| Algorithm | Memory per client | Allows bursts | Boundary problem | Typical use |
|---|---|---|---|---|
| Token bucket | Two numbers | Yes, up to the bucket size | None | API gateways, SDK retries |
| Fixed window | One counter | Yes, and twice the limit at a boundary | Yes | Simple quotas, logging |
| Sliding log | One timestamp per request | No more than the limit in any window | None | Low-volume exact limits |
| Sliding counter | Two counters | Close to the limit, approximate | Mostly fixed | Edge and CDN rate limiting |
Frequently asked questions
Which rate limiting algorithm should I use?
Token bucket for most APIs: it allows short bursts, smooths to a steady rate, and needs only two numbers per client. Use a sliding counter when you need an upper bound that is close to exact with constant memory, and a sliding log only when the exact count matters and volumes are small.
What is the problem with a fixed window counter?
Traffic at the edges of two adjacent windows is not limited together. A client can send the full limit at 0:59 and the full limit again at 1:00, so a one-second span carries twice the allowance. Sliding windows exist to close that gap.
What is the difference between token bucket and leaky bucket?
They are mirror images. A token bucket lets requests through immediately while tokens last, so bursts pass. A leaky bucket queues requests and drains them at a fixed rate, so the output is perfectly smooth and bursts wait or are dropped. Token bucket limits the rate; leaky bucket shapes it.
How do I pick the limit and window?
Start from what a well-behaved client needs, not from what the backend can take. A mobile app that polls every 30 seconds needs 2 requests a minute, so 10 per minute leaves room for retries. The window sets how long a client waits after being cut off; shorter windows feel fairer but smooth less.
Where does the rate limiter live in a real system?
Usually in the API gateway or a middleware in front of the service, with the counters in a shared store such as Redis so every instance sees the same numbers. Per-instance limiters are simpler but multiply the effective limit by the number of instances.