This question evaluates understanding of sliding-window rate limiting, time-windowed counting, and per-user state management for high-throughput services.
Implement a sliding-window log rate limiter.
Design a class RateLimiter initialized with:
maxRequests
(e.g., 100)
windowMillis
(e.g., 60_000)
Implement:
boolean allow(String userId, long timestampMillis)
For each userId independently:
true
if the number of allowed requests in the time interval
(timestampMillis - windowMillis, timestampMillis]
is
strictly less than
maxRequests
.
true
, record this request as allowed.
false
and do not record it.
10^5
calls.
userId
.