Token bucket
A rate limiting algorithm that allows bursts up to a bucket size and then a steady rate of requests.
Definition
A bucket holds up to a fixed number of tokens and refills at a constant rate. Each request takes a token; when the bucket is empty, requests are rejected until tokens drip back in. The bucket size sets the largest burst, and the refill rate sets the long-term limit. It needs only two numbers per client: the token count and the time of the last refill, which is calculated on each request rather than by a timer.
In practice
A bucket of 10 tokens refilled at one token every 6 seconds lets a quiet user send 10 requests at once, then about 10 per minute.
Learn it in context
Lessons that use this term.