rate limiting
Leaky Bucket
Requests fill a bucket that drains at a constant rate — smooths bursty traffic
Bucket Level0.00 / 8
Leak Rate1.2/s
Allowed0
Rejected0
bucket
↓ requests
·
empty
Fill Level
0.00 / 8 — draining at 1.2/s
output rate: 0 req/s (constant, regardless of input burst)
// events
No requests yet.
// how it works
Think of a bucket with a small hole at the bottom:
- Requests add water to the bucket (level increases)
- Water leaks out at a constant rate: elapsed × leakRate
- If level + 1 > capacity → request rejected (overflow)
- Output is always at a steady rate, smoothing bursts
// trade-offs
- Smooths bursty traffic into steady output
- O(1) time and space
- Great for queue-based processing
- No controlled bursting — rejects excess immediately
- Can be too strict for bursty workloads