Token and leaky buckets
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
explain the main algorithms and their burst behavior.
Planned topics
- Token bucket: tokens refill at a rate up to a capacity; each request uses one. Allows bursts up to capacity.
- Leaky bucket: requests enter a queue that drains at a fixed rate; smooths output, drops overflow.
- Fixed window: count per minute; simple, but allows a double burst at the window edge.
- Sliding window: counts over the last N seconds; fairer, costs more memory.
- Choose token bucket for typical APIs: simple and burst-friendly.
Draft outline details
Demonstration
// token bucket, refill 10/s, capacity 20
double tokens = Math.min(capacity, tokens + elapsedSeconds * 10);
if (tokens >= 1) { tokens -= 1; allow(); } else reject();Check your understanding
Which algorithm allows a short burst yet limits the average rate?
Show answer
Token bucket.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.