Course contentsShow
← System Design
Lesson 965 of 1,91925. Rate Limiting and ThrottlingFree lesson

Leaky Bucket Algorithm

How leaky bucket processes requests at a constant rate, smoothing traffic spikes by queuing excess requests.

Leaky Bucket Algorithm

What You'll Learn

You'll learn how the leaky bucket algorithm processes requests at a constant, steady rate—regardless of incoming traffic bursts—by queuing excess requests and "leaking" them out uniformly.

How It Works

Imagine a bucket with a small hole at the bottom. Water (requests) pours in at varying rates—sometimes a trickle, sometimes a flood. The bucket collects this water, but it always drips out at a fixed, constant rate through the hole, no matter how full the bucket is.

Core Mechanism

  1. Requests arrive at unpredictable rates (bursty traffic)
  2. Requests enter the bucket (a queue) if there's room
  3. Requests are processed (leak out) at a constant rate—say, 100 requests per second
  4. If the bucket overflows (queue is full), new requests are rejected

Key Characteristics

Unlike the token bucket which allows brief bursts, the leaky bucket smooths traffic completely. It doesn't matter if 1,000 requests arrive in one second—they'll still be processed at exactly your configured rate (e.g., 100/sec). The excess waits in the queue or gets dropped.

This creates predictable, uniform load on downstream services, preventing sudden spikes from overwhelming your system.

When to Use It

The leaky bucket excels when you need strict traffic shaping:

  • Protecting legacy systems with fixed capacity
  • Meeting SLAs requiring steady throughput
  • Network traffic shaping where consistency matters more than responsiveness

The tradeoff? Increased latency during bursts, since requests must wait their turn in the queue.

Key Takeaway: The leaky bucket algorithm enforces constant-rate processing by queuing incoming requests and releasing them at a fixed pace, effectively smoothing all traffic spikes into a predictable stream.