Rate Limiter Token Bucket Calculator
Size a token-bucket rate limiter: sustained throughput, burst capacity and how long a full bucket lasts under a given request rate.
How it works
Sustained rate = refill rate · Burst = bucket capacity · If request rate > refill: drain time = capacity ÷ (request rate − refill rate)
A token bucket allows short bursts up to its capacity while enforcing a long-run average equal to the refill rate. Each request spends a token; tokens replenish at the refill rate, so as long as incoming traffic stays at or below that rate the bucket never empties and nothing is throttled. When traffic exceeds the refill rate, the surplus drains the bucket at the difference between the two rates — once empty, callers are limited to exactly the refill rate.
Worked example
A 100-token bucket refilling at 10/s facing 15 req/s drains at 15 − 10 = 5 tokens/s, so a full bucket lasts 100 ÷ 5 = 20 seconds of burst before requests are throttled down to the sustained 10/s.
Frequently asked questions
What is the difference between token bucket and leaky bucket?
A token bucket permits bursts up to its capacity and then falls back to the refill rate, so it is bursty-friendly. A leaky bucket drains at a fixed rate regardless, smoothing traffic to a constant output with no bursts.
How do I choose capacity and refill rate?
Set the refill rate to the sustained throughput your backend can handle, and the capacity to the largest legitimate burst you want to allow (for example, a page that fires several requests at once). Too large a capacity lets abusive bursts through; too small blocks normal spikes.
What happens when the bucket is empty?
New requests either wait until enough tokens accrue or are rejected immediately, usually with an HTTP 429 and a Retry-After header telling the client how long until a token is available.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.