🎯 Real InterviewMediumVerifiedAlgorithm ProblemCoding Ready
Rate Limiter Implementation
Implement a rate limiter class with sliding window algorithm
Rate LimiterSystem DesignTypeScriptSliding WindowReal Interview
Updated Dec 22, 2025
Question
Rate Limiter Implementation
Difficulty: Medium
Estimated Time: 30-45 minutes
Tags: System Design, TypeScript, Sliding Window, Data Structures
Source: Real Interview Question
Problem Statement
Implement a rate limiter class in TypeScript (or your chosen language) that restricts a given user to a maximum number of requests in a given time window (e.g., 100 requests per minute).
For now, assume this code runs on a single server.
Write a test function to show that your logic works.
Requirements
- Create a
RateLimiterclass - Support configurable max requests and time window
- Track requests per user (by user ID)
- Return
trueif request is allowed,falseif rate limited - Include a test function demonstrating the functionality
Example Usage
const limiter = new RateLimiter(100, 60000); // 100 requests per minute
limiter.allowRequest('user123'); // true
limiter.allowRequest('user123'); // true
// ... after 100 requests
limiter.allowRequest('user123'); // false (rate limited)
Constraints
- Single server (no distributed considerations)
- Time window is sliding (not fixed buckets)
- Memory efficient for many users
- O(1) or O(log n) time complexity for allowRequest
Your Solution
python
Auto-saves every 30s
Try solving the problem first before viewing the solution
0:00time spent