← Lessons

quiz vs the machine

Gold1410

System Design

The Leaky Bucket Algorithm

Queue requests and drain them at a constant rate to smooth bursty traffic into a steady stream.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the defining property of the leaky bucket output?

2. How does leaky bucket differ from token bucket at the output?