How it works
A leaky bucket models requests as water poured into a bucket with a hole. Requests enter a queue of fixed size and are processed, or leak out, at a constant rate. If the queue is full when a request arrives, that request is dropped, the overflow.
The defining trait is a smooth, constant output rate regardless of how spiky the input is. The bucket absorbs short bursts into the queue and releases them evenly.
Token bucket versus leaky bucket
- Token bucket can emit a burst at the output, up to its capacity, then slow down.
- Leaky bucket enforces a steady output and never bursts; it shapes traffic into a constant stream.
Leaky bucket is favored when a downstream system needs a predictable, even load, such as a payment processor or a hardware queue.
Key idea
A leaky bucket queues requests and drains them at a constant rate, smoothing bursts into a steady output stream.