An Interactive Guide To Rate Limiting
Learn about rate limiting algorithms with interactive apps, including Token Bucket, Leaky Bucket, Fixed Window, and Sliding Window methods

Introduction
Rate limiting is an essential strategy for every backend application. It prevents a single user or client from overwhelming resources and degrading service quality for everyone else. Here are some of the primary benefits of rate limiting:
-
Prevents resource starvation by ensuring fair API usage across all consumers.
-
Reduces hosting and infrastructure costs by bounding peak loads.
-
Provides baseline protection against Denial of Service (DoS/DDoS) and brute-force attacks.
I have created four interactive apps below that let you experiment with the most common rate limiting algorithms.
Token Bucket
How It Works
-
A bucket holds a fixed maximum number of tokens.
-
New tokens are added to the bucket at a constant refill rate.
-
When a request arrives:
-
If a token is available, one token is consumed and the request is processed.
-
If no tokens are available, the request is immediately rejected (HTTP 429) or queued.
-
-
Key characteristic: Allows for short, configurable bursts of traffic as long as enough tokens have accumulated.
I have created an interactive app that lets you experiment with the Token Bucket algorithm:
Leaky Bucket
How It Works
-
Imagine a bucket with a small hole at the bottom that leaks water at a steady, fixed rate.
-
Incoming requests are added to the bucket like drops of water.
-
Requests are processed (or "leaked") at a constant, smooth rate.
-
If the bucket fills to maximum capacity when a new request arrives, the overflow is dropped.
-
Key characteristic: Smooths out traffic bursts and outputs a steady stream of requests to downstream services.
I have created an interactive app that lets you experiment with the Leaky Bucket algorithm:
Fixed Window Counter
How It Works
-
Time is divided into fixed-size chronological windows (e.g., 1 minute or 1 hour).
-
A counter tracks the total number of requests made by a client within the current window.
-
If the counter exceeds the allowed threshold, subsequent requests are blocked until the next window begins.
-
Key characteristic: Extremely simple and memory-efficient, but susceptible to traffic bursts (up to 2x the limit) at the boundary between adjacent windows.
I have created an interactive app that lets you experiment with the Fixed Window algorithm:
Sliding Window Counter
How It Works
-
Maintains a rolling time window by tracking request timestamps or combining previous and current window counts.
-
When a request arrives, the system calculates how many requests occurred in the sliding interval preceding the current moment.
-
If the count is within the limit, the request is permitted; otherwise, it is throttled.
-
Key characteristic: Prevents the boundary burst issue of fixed windows while maintaining high accuracy and smooth rate limiting.
I have created an interactive app that lets you experiment with the Sliding Window algorithm: