In a Lua script (or MULTI/EXEC pipeline), remove timestamps older than now - window with ZREMRANGEBYSCORE, check ZCARD < limit, add the current unique member (timestamp + uuid) with ZADD, and set PEXPIRE so idle keys expire. Executing inside Lua guarantees atomicity across workers.
Follow-up Interview Question · What is the memory overhead of a ZSET per user vs a token-bucket or sliding-window counter?