Redis medium
Which Redis implementation allows for tracking 'Daily Active Users' using exactly 1 bit per User ID to minimize RAM consumption?
- A Hash: Storing a boolean flag 'active: true' for every unique User ID record in a global analytical map.
- B List: Appending a numeric User ID to a chronological feed every time a customer logs into the system.
- C Bitmap: Using the `SETBIT` command to toggle bits in a binary-safe string where the offset is the ID.
- D HyperLogLog: Estimating the total count of active sessions using a fixed 12KB probabilistic buffer.
Answer: C. Bitmap: Using the `SETBIT` command to toggle bits in a binary-safe string where the offset is the ID.
Bitmaps are incredibly space-efficient for boolean tracking. Tracking 100 million users for a single day takes only ~12.5 MB of RAM. You can then use `BITOP` to perform fast AND/OR operations across multiple days.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- If the Redis memory limit is reached, what specific behavior is exhibited by the `allkeys-lru` eviction policy?
- What is the defining characteristic of a Redis 'Set' data type compared to a standard Redis 'List'?
- In the context of Redis messaging, what is the functional definition of the 'Pub/Sub' feature?
- How does the Redis background snapshotting process (`BGSAVE`) leverage the operating system's `fork()` mechanism to minimize memory overhead?
- Why does Redis proactively disconnect a Pub/Sub client that exhibits high 'output buffer' usage relative to its ingestion rate?
- How does a 'Sorted Set' (ZSET) manage its internal membership and ordering differently from a plain Set?