Learning pathsA
Design exercises

Design a rate limiter

Represent time and atomic consumption explicitly.

Understand the problem

A token bucket refills up to capacity at a configured rate. Each request consumes one token if available. Use a monotonic clock for local elapsed time and an atomic shared update for distributed state.

Make it concrete

Capacity 10 and refill 2/sec permits a short burst of 10 followed by a sustained 2/sec.

Trade-offs and pitfalls

A fixed window is simpler but allows a burst at the boundary.

Check your understanding

Write tests for refill, burst limits, and concurrent requests.

Practice this topic

Your study notes