Redis medium
Which data structure is most appropriate for approximating the unique visitor count of 100 million users while consuming only 12KB of RAM?
- A Set: Storing explicit user IDs to ensure 100% accuracy for membership and intersection queries.
- B HyperLogLog: An probabilistic structure that estimates cardinality with a standard error of 0.81%.
- C Hash: Mapping unique user handles to their respective visit counts for detailed analytical tracking.
- D List: Appending every raw visit event as a unique string element to preserve chronological history.
Answer: B. HyperLogLog: An probabilistic structure that estimates cardinality with a standard error of 0.81%.
A Set of 100 million IDs would consume gigabytes of RAM. HyperLogLog is a probabilistic tool that uses bitwise estimation to provide a 'good enough' count for massive data streams with constant memory.
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?