Challenge - 5 Problems
Sliding Window Rate Limiting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Sliding Window Rate Limit: Count Requests in Last Minute
Given a Redis sorted set where each member is a timestamp of a user request, which command returns the count of requests made in the last 60 seconds?
Redis
ZCOUNT user:123:requests -inf +infAttempts:
2 left
💡 Hint
Use ZCOUNT with a score range to count timestamps within the last 60 seconds.
✗ Incorrect
ZCOUNT with the range from (current_timestamp - 60) to current_timestamp counts all requests in the last 60 seconds. Using +inf or -inf incorrectly includes timestamps outside the window.
📝 Syntax
intermediate2:00remaining
Identify the Correct Redis Command Syntax for Sliding Window Cleanup
Which Redis command syntax correctly removes all request timestamps older than 60 seconds from the sorted set 'user:123:requests'?
Attempts:
2 left
💡 Hint
You want to remove all timestamps less than (current_timestamp - 60).
✗ Incorrect
ZREMRANGEBYSCORE with range -inf to (current_timestamp - 60) removes all older timestamps. Other options either remove wrong ranges or have syntax errors.
❓ optimization
advanced3:00remaining
Optimize Sliding Window Rate Limiting with Redis Lua Script
Which Lua script snippet atomically adds the current timestamp to a sorted set, removes timestamps older than 60 seconds, and returns the count of requests in the last 60 seconds?
Attempts:
2 left
💡 Hint
Remove timestamps older than (current_timestamp - 60) and count timestamps in the last 60 seconds.
✗ Incorrect
Option D correctly removes old timestamps and counts requests in the last 60 seconds. Other options remove wrong ranges or count incorrectly.
🔧 Debug
advanced2:30remaining
Debug Sliding Window Rate Limiting: Unexpected High Count
A developer uses this Redis command to count requests in the last 60 seconds:
but notices the count is unexpectedly high. What is the cause?
ZCOUNT user:123:requests -inf (current_timestamp - 60) but notices the count is unexpectedly high. What is the cause?
Attempts:
2 left
💡 Hint
Check the score range used in ZCOUNT and what it includes.
✗ Incorrect
Using -inf to (current_timestamp - 60) counts all timestamps older than 60 seconds ago, causing a high count. The correct range should be from (current_timestamp - 60) to current_timestamp.
🧠 Conceptual
expert3:00remaining
Why Use Sliding Window Rate Limiting Over Fixed Window?
Which statement best explains the advantage of sliding window rate limiting compared to fixed window rate limiting?
Attempts:
2 left
💡 Hint
Think about how requests are counted over time in both methods.
✗ Incorrect
Sliding window counts requests in a continuously moving time frame, preventing sudden bursts at window boundaries that fixed windows allow. This makes it more precise and fair.