Databases · Senior · Question 36 of 75
How can you count unique visitors over huge data sets cheaply when approximate results are fine?
- 1Store every visitor ID in a list and count it
- 2Use
COUNT(*)on the raw table every time - ✓Correct answer: Use a HyperLogLog sketch (e.g. Redis
PFADD/PFCOUNT), which estimates distinct counts with tiny memory
Explanation
HyperLogLog keeps about 12 KB per counter in Redis with around 1% error. Sketches can also be merged across days or shards.