Member-only story
Counting 100 Million Unique Riders With 12 KB of Memory: How Approximate Counting Works
Shree Kavya
7 min read1 day ago
An exact distinct count has to remember every ID. HyperLogLog remembers 16,384 small numbers and lands within 1%. The idea, a from-scratch build in Python, and when “approximately right” is the better engineering choice
Press enter or click to view image in full size The estimate’s error stays inside a narrow band as the count grows.
On Monday we saw that distinct counts don’t add up: at RideLoop , our fictional bike-taxi app, seven daily counts of unique riders summed to 75,000 when the real weekly number was under 30,000. To get the right answer, you have to count distinct IDs across the whole week again.
That’s fine at 30,000. At 100 million it hurts. COUNT(DISTINCT rider_id) has to see every distinct ID in one place to know whether it has seen it before.…