Rate Limiter Algorithm

What is Rate Limiting?

Rate limiting is a technique used to control the amount of incoming or outgoing traffic to or from a network, application, or resource over a specific period. It's crucial for:

Rate limiters typically track requests based on identifiers like user ID, IP address, API key, etc., and enforce predefined limits.

Common Rate Limiting Algorithms

1. Token Bucket

Imagine a bucket with a fixed capacity that holds tokens. Tokens are added to the bucket at a fixed refill rate.

2. Leaky Bucket

This algorithm uses a queue (the bucket) with a fixed capacity. Requests are added to the queue as they arrive. The bucket "leaks" requests out at a fixed leak rate, processing them.

3. Fixed Window Counter

This is a simpler approach. Time is divided into fixed windows (e.g., 60 seconds). A counter tracks requests within the current window.

4. Sliding Window Log

This algorithm addresses the boundary issue of Fixed Window by keeping a log of request timestamps within the current window duration.

Visualize and Play

Select an algorithm, configure its parameters, and send requests to see how rate limiting works.

Click repeatedly to test limits.
Status

Token Bucket State

Tokens: 0 / 10

Leaky Bucket State

Queue Size: 0 / 5

Fixed Window State

0
Requests in Current Window (Limit: 5)
Time Remaining: 10.0s

Sliding Window Log State

Requests in last 10s: 0 (Limit: 5)
Log messages will appear here...