Wiki: Breaking Down Our Billion User Reach with HyperLogLog
For agents: Markdown version · Wiki index · Explore
- Speaker: Daniel Avramson
- Event: Reversim Summit 2019
- Video: https://www.youtube.com/watch?v=uokr9WbYm10
- Transcript: /transcripts/2019/05-uokr9WbYm10.md
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: Algorithms, Databases, Data Engineering, Data Science
Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.
Summary
The speaker discusses how to efficiently calculate approximate distinct user counts over massive datasets using the HyperLogLog probabilistic data structure. Traditional exact counting methods such as SQL count distinct fail to scale due to O(N) memory complexity and the inability to merge results from distributed partitions. By leveraging HyperLogLog, the engineering team managed to reduce storage requirements to under a gigabyte per day while enabling flexible aggregations across multiple dimensions. The audience learns the core mechanics of probabilistic estimation, bit-pattern observations, and how mergeable data structures solve big data challenges.
Key points
- 1:10 Exact counting methods like SQL count distinct require tracking every user, leading to O(N) memory complexity and unmergeable results across distributed systems.
- 4:25 The HyperLogLog algorithm published in 2007 provides sub-linear space complexity and allows results to be easily merged.
- 6:34 Probabilistic estimation uses observations of rare events, such as finding the tallest person in a room, to reliably estimate total population size.
- 9:43 The algorithm applies a deterministic hash function to convert user IDs into bit sequences with a uniform distribution.
- 14:07 To reduce estimation variance, HyperLogLog uses stochastic averaging by dividing elements into buckets and applying harmonic means.
- 22:56 Data structures can be easily merged by taking the maximum value for each bucket index across arrays, allowing distributed computation.
- 24:01 Using an open-source sketches library with sparse representation compressed over 5 million dimension combinations into just 800 megabytes per day.
Takeaways
- Use probabilistic data structures like HyperLogLog when exact counts are not legally or financially required but large-scale approximations are sufficient.
- Leverage mergeable sketches to pre-aggregate data by dimensions and combine them dynamically at query time.
- Choose harmonic mean-based estimators to minimize the impact of outliers on probabilistic estimates.
Questions this talk answers
- How can I calculate distinct user counts across large datasets without running out of memory?
- What is the difference between exact counting and probabilistic cardinality estimation?
- How do mergeable data structures enable flexible multi-dimensional big data aggregations?
Technologies
Redis, BigQuery
Tags
aggregations, algorithms, big data, data structures, distributed systems, performance