In Redis, the INCR command is often used in rate limiting. What is the primary role of INCR in this context?
Think about how you count the number of times something happens.
The INCR command increases the value of a key by one. In rate limiting, it counts how many requests have been made.
In a Redis-based rate limiter, why is the EXPIRE command used alongside INCR?
Consider how to limit requests within a time frame.
EXPIRE sets a time-to-live on the key so the counter resets after the time window, enabling fixed window rate limiting.
When multiple clients send requests simultaneously, what is the best way to ensure atomicity of INCR and EXPIRE commands in Redis rate limiting?
Think about how to make multiple commands run as one indivisible operation.
Using MULTI/EXEC or Lua scripts ensures INCR and EXPIRE run together atomically, preventing race conditions.
Which of the following is a known limitation when implementing rate limiting using only INCR and EXPIRE in Redis?
Consider the difference between fixed window and sliding window rate limiting.
INCR and EXPIRE implement fixed window counters, which can cause bursts at window edges and do not support precise sliding windows.
You want to rate limit 1 million users with a 1-minute window using Redis keys with INCR and EXPIRE. Each key stores a counter as a 64-bit integer. Estimate the approximate memory usage in megabytes (MB) for storing all counters simultaneously.
Consider key overhead, value size, and approximate Redis memory usage per key.
Each key-value pair in Redis has overhead (~50 bytes) plus 8 bytes for the integer. For 1 million keys, ~58 MB plus additional overhead (hash table, key strings) typically totals about 100 MB.