Token Bucket Rate Limiting
Send requests and advance simulated time to distinguish burst capacity, refill rate and strict token-based admission from a queue or fixed-window counter.
Free theory articleSend requests and advance simulated time to distinguish burst capacity, refill rate and strict token-based admission from a queue or fixed-window counter.
Concept & interpretation
Consider an API token bucket starting with a full bucket of 5 tokens. The refill rate is 2 tokens/sec, and each request costs 2 tokens. We can trace the token balance through a series of events:
Experiment
You can try this out in the Token Bucket Rate Limiting module:
- Set the Capacity to 5, the Refill Rate to 2, and the Request Cost to 2.
- Click Reset Simulation to start with a full bucket of 5 tokens.
- Click Send Request three times. Notice that the first two are accepted, and the third is rejected.
- Click Advance 1s to refill the bucket by 2 tokens.
- Click Send Request once more. Notice that it is accepted.
- Click Advance 1s multiple times and observe the tokens capping strictly at 5 without exceeding the limit.