Skip to main content
InterviewHubPRO
Section Overview
Q48

Question 48 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

96%
Redis & Caching (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

Rate Limiting with Sliding Window Log (ZSET).

senior LevelMost AskedredisAdvanced Internals

In Simple Words: Fixed-window rate limiters suffer from 2x traffic spikes at window boundaries. Sliding Window Log uses a Redis Sorted Set:

  1. Store timestamp as both member and score: ZADD rate:user1 <now> <now>.
  2. Remove timestamps older than window: ZREMRANGEBYSCORE rate:user1 0 (<now> - 60).
  3. Count remaining requests: ZCARD rate:user1. If $< 100$, allow request!