Token Bucket
Allows a burst up to the bucket size, then enforces an average rate.
How it works
The bucket starts full. Each allowed request spends one token. Tokens return continuously at the refill rate and never stack past capacity. An empty bucket rejects until one token has dripped back.
Try this
Send a burst of 10. The bucket empties and the rest are denied. Wait — tokens return at the refill rate, and single requests start passing again.
Pros
- · Allows controlled bursts
- · Smooth long-run rate
- · Cheap: two numbers of state
Cons
- · A full bucket can stampede a downstream service
- · Capacity and refill rate both need tuning