.NET Architecture & System Design Interview Question #137

What is the Token Bucket rate-limiting algorithm?

Resilience, Rate Limiting, Health Checks & Observability Senior Advanced

Quick Interview Answer

Token Bucket maintains a bucket containing tokens that are replenished at a configured rate. Each accepted request consumes a token.

Detailed Explanation

Token Bucket maintains a bucket containing tokens that are replenished at a configured rate. Each accepted request consumes a token.

The algorithm allows controlled bursts when tokens have accumulated while enforcing the long-term average rate. Bucket capacity determines the maximum burst size.

Code Example

Bucket capacity = 10
Refill = 2 tokens/sec

Request consumes 1 token.
No token -> wait/reject.