CodingMedium78% interview frequency · Last seen 2025-11

Design a Rate Limiter

Problem

Implement a rate limiter that restricts a user to at most N requests per window of T seconds.


Your class should support:

- `RateLimiter(int maxRequests, int windowSeconds)`

- `boolean allowRequest(String userId)` — returns true if the request is allowed, false if rate limited


Assume a single-machine deployment for now. Requests from the same userId within the window count toward the limit.

Common follow-ups

  • How would you scale this across multiple servers?
  • What trade-offs exist between token bucket and sliding window approaches?

Practice

Sign in to unlock practice

Create a free account for full access through 2027 — study guides, follow-ups, and an in-browser code editor. Part of our AI bubble promotion; feedback is appreciated.