Implement a leaky-bucket rate limiter
Company: Box
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Onsite
Implement a leaky-bucket rate limiter that enforces a maximum average request rate with a fixed drain rate. Write unit tests to validate steady-state, burst, and boundary conditions. Discuss how you would make the limiter safe under concurrency (multiple threads/processes) and how you would extend it for a distributed setting (e.g., shared state via Redis or a durable store), including consistency and failure-mode considerations.
Quick Answer: This question evaluates understanding of rate-limiting algorithms (leaky-bucket semantics), resource accounting (capacity and drain rate), timing precision, concurrency control, testing, and distributed coordination.