Implement a Rate Limiter

Quick Overview

Implement a rate limiter that supports fixed window, sliding window, and token bucket strategies. Design a clean API and handle edge cases around window boundaries.

Intuit
Coding & Algorithms
Software Engineer
Intuit
Software Engineer
Phone Screen
Coding & Algorithms
Medium

7


Implement a rate limiter that supports fixed window, sliding window, and token bucket strategies. Design a clean API and handle edge cases around window boundaries.

Common in phone screens. Intuit's APIs serve millions of small businesses, and rate limiting protects both platform stability and fair resource allocation across tenants.

What the Interviewer Expects
  • Implement at least two rate limiting strategies with a clean interface
  • Handle edge cases around window boundaries and concurrent requests
  • Write production-quality code with proper naming and structure
  • Discuss time and space complexity for each strategy
  • Consider distributed rate limiting across multiple servers
Key Topics to Cover
Rate Limiting
Sliding Window
Token Bucket
API Design
Concurrency
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you implement this in a distributed system with multiple server instances?
  • How do you handle rate limit headers in HTTP responses?
  • What strategy works best for API rate limiting vs. login attempt throttling?
  • How would you implement per-tenant rate limits with different tiers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Approach

Define a RateLimiter interface with an allow(key: str) -> bool method. Implement FixedWindowRateLimiter using a dictionary mapping (key, window_start) to count. Implement SlidingWindowRateLimiter us...

Implementation Details

For the sliding window approach, maintain a deque of request timestamps per key. On each request, remove expired entries (older than window size), check if the count is below the limit, and if so, add...


Submit Your Answer
Markdown supported

Related Questions