RL
GitHub
Technical Comparison

Four Approaches to Limiting

Each algorithm trades off between complexity, precision, and computational overhead. Choose based on your traffic patterns and requirements.

All algorithms execute atomically in Redis using Lua scripts.

Token Bucket

Tokens accumulate at a constant rate. Requests consume tokens. When empty, requests are blocked.

Key Characteristics

● Accuracy: High
● Memory: Very Low
● Burst: Controlled

Best For

REST APIs with variable traffic patterns and acceptable burst traffic

Learn More →

Configuration

yaml
algorithm: TOKEN_BUCKET
capacity: 100
refillRate: 10  # tokens per second

Leaky Bucket

Incoming requests are queued. Processed at a constant rate. Smooths traffic spikes into steady flow.

Key Characteristics

● Accuracy: High
● Memory: Low
● Burst: Smoothed

Best For

Database queries, message queues, or systems needing predictable output flow

Learn More →

Configuration

yaml
algorithm: LEAKY_BUCKET
capacity: 50
flowRate: 5  # requests per second

Fixed Counter

Count requests in fixed time window. Reset happens at window boundaries.

Key Characteristics

● Accuracy: Medium
● Memory: Very Low
● Burst: Cliff effect

Best For

Simple APIs, internal services, or where absolute simplicity is preferred

Learn More →

Configuration

yaml
algorithm: FIXED_COUNTER
maxRequests: 1000
windowSize: 60  # seconds

Sliding Window

Continuously sliding window without resets. Most accurate. Every request checks entire window.

Key Characteristics

● Accuracy: Very High
● Memory: Medium
● Burst: Prevented

Best For

Strict SLA enforcement, billing systems, or any critical application

Learn More →

Configuration

yaml
algorithm: SLIDING_WINDOW
maxRequests: 100
windowTime: 60000  # milliseconds

Detailed Comparison

Head to Head

MetricToken BucketLeaky BucketFixed CounterSliding Window
AccuracyHighHighMediumVery High
Burst HandlingControlledSmoothedCliff EffectPrevented
Memory UsageVery LowLowVery LowMedium
Redis Ops/Check3334
CPU OverheadLowLowVery LowMedium
ComplexityMediumMediumLowHigh

How to Choose

Decision Matrix

Do you allow burst traffic?

Use Token Bucket for flexibility. Use Sliding Window if precision is critical.

Must output be consistent?

Use Leaky Bucket. It guarantees constant processing rate.

Do you prioritize simplicity?

Use Fixed Counter. Fast, simple, good for internal APIs.

Is billing/SLA involved?

Use Sliding Window. The most accurate available algorithm.

Each algorithm is available in the playground. Test them with mock mode or connect to your own backend.