Problem Statement
Which approach implements a true sliding window for per-user limits?
Explanation
A sliding log keeps each request time and trims those outside the window. The current count equals items within the last W seconds. It is accurate but costs more CPU and memory.
A compromise is a rolling window with a few sub-buckets, which balances accuracy and efficiency.
Code Solution
SolutionRead Only
ZADD user:req now now; ZREMRANGEBYSCORE user:req 0 now-W; ZCARD user:req;
