Counting 10 million unique visitors
I only heard about HyperLogLog this week, when I looked at how PostHog counts the unique people who open a campaign email.
So I tried it in Redis with 10 million user IDs, each added twice. A Set, which stores every ID, gave the exact count and used 433 MB. HyperLogLog said 10,044,722, which is 0.45% off, and used 14 KB.
The idea is coin flips. If your longest run of heads is 3, you probably flipped a handful of times. If it's 20, you flipped around a million times. HyperLogLog hashes each ID and keeps only the longest run of zeros at the start of the hash. To smooth out luck it does this in 16,384 buckets and averages them. Those counters take about 12 KB, and adding more users or the same user again doesn't make them bigger.
In Redis it's 2 commands: PFADD visitors:2026-11-17 user_42 PFCOUNT visitors:2026-11-17
I'd use it for unique visitors or daily active users, where a count that's about 1% off is fine. I wouldn't put its numbers on an invoice.