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?
Solution
# Solution locked # Sign in to unlock expert solutions # with multi-language code and analysis
Sign in to unlock
Create a free account to preview problems. Subscribe for full access to our curated bank — expert tutorials, follow-ups, and practice tools you won't find on public sites.