educative.io

How much memory would we need to store all of the user data for sliding window?

How much memory would we need to store all of the user data for sliding window? Let’s assume ‘UserID’ takes 8 bytes. Each epoch time will require 4 bytes. Let’s suppose we need a rate limiting of 500 requests per hour. Let’s assume 20 bytes overhead for hash-table and 20 bytes overhead for the Sorted Set. At max, we would need a total of 12KB to store one user’s data:

8 + (4 + 20 (sorted set overhead)) * 500 + 20 (hash-table overhead) = 12KB

would it be a good idea to reduce the memory requirement by tracking per second instead of per hour? then, we would only need 8 (~500/60) timestamps per user, instead of 500.