PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/Box

Implement a leaky-bucket rate limiter

Last updated: Apr 17, 2026

Quick Overview

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.

  • hard
  • Box
  • System Design
  • Software Engineer

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.

Related Interview Questions

  • Identify and fix deadlock in locked code - Box (medium)
  • Explain and diagram your past system architecture - Box (hard)
  • Diagnose failures via SSH and large logs - Box (medium)
Box logo
Box
Aug 1, 2025, 12:00 AM
Software Engineer
Onsite
System Design
36
0

Implement a Leaky-Bucket Rate Limiter with Tests and Distributed Design

Context and Assumptions

  • Implement in a general-purpose language; the reference solution uses Python 3 for clarity and unit tests.
  • Leaky bucket semantics: a fixed drain rate r units/sec, a finite capacity b units. Each request consumes 1 unit unless specified otherwise. The bucket "leaks" continuously at rate r.
  • The limiter should support:
    1. try_acquire(n=1) that returns whether a request of size n is allowed now and, if not, the wait time until it would be allowed.
    2. Unit tests for steady-state, burst, and boundary conditions.
    3. Discussion of concurrency safety (multi-thread/process) and distributed extension (e.g., Redis) with consistency & failure-mode considerations.

Task

  1. Implement a leaky-bucket rate limiter enforcing a maximum average request rate with a fixed drain rate.
  2. Write unit tests to validate:
    • Steady-state behavior at/under the configured rate.
    • Burst behavior up to capacity.
    • Boundary/edge conditions (precision, zero/near-zero time deltas, exact thresholds).
  3. Explain how to make the limiter safe under concurrency.
  4. Propose a design to extend it in a distributed setting (e.g., Redis), including consistency and failure-mode considerations.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Box•More Software Engineer•Box Software Engineer•Box System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.