~learn.
0:00 / 1:08
W08 · Analytics pipeline

Add up 30 days of unique viewers, and you get the wrong number

transcript

A creator asks: how many unique viewers in the last 30 days? You have a unique count for every day. Just add them up?

The 30 day summary comes from the daily rollup. Total views? Sum the days. Fine. Watch hours? Same. They add up. Unique viewers is the one that doesn't.

Take one viewer. Day 1, they watch. One unique viewer that day. Day 2, they're back. Unique again, for that day. They watch on 5 days in total. Add the days up, and one person counts as 5.

That sum isn't viewers. It's viewer-days. Everyone who comes back gets counted again. The more they return, the bigger the error.

So each day also stores a HyperLogLog sketch. Sketches merge across days. Merge all 30. Each viewer counts once. Approximate, but not inflated.

Counts add up. Unique counts don't. So store a sketch per day, and merge them. Approximate, never inflated.

Full breakdown in the lecture.