---
title: "How YouTube Counts Millions of Live Viewers"
url: https://daily.dev/posts/how-youtube-counts-millions-of-live-viewers-l3kj0h2bq
source_url: https://code.likeagirl.io/how-youtube-counts-millions-of-live-viewers-cf91637b8dd1
type: article
source: "Code Like A Girl"
published: 2026-08-13T07:38:53.541Z
updated: 2026-08-13T07:39:19.681Z
tags: ["career", "algorithms", "redis", "data-structures"]
reading_time: 4
upvotes: 3
comments: 1
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How YouTube Counts Millions of Live Viewers

**[Code Like A Girl](https://daily.dev/sources/colkgirl)** · 4 min read · 3 upvotes · 1 comments

## Summary

Explains how large-scale live viewer counts, like YouTube's during a FIFA World Cup stream, are estimated using the HyperLogLog probabilistic algorithm rather than an exact HashMap. Breaks down the mechanism: hashing IDs, counting trailing zero-streaks, bucketing into registers to reduce variance, and aggregating via harmonic mean. Notes Redis implements this with 16,384 registers in just 12 KB of memory, achieving cardinality estimates up to 2^64 with ~0.81% standard error. Also covers where HyperLogLog fits (analytics dashboards, query planners, cache management) and where exact counting is still required (financial/audit systems).

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://code.likeagirl.io/how-youtube-counts-millions-of-live-viewers-cf91637b8dd1>

## Questions this post answers

### How does HyperLogLog estimate the number of unique items without storing them?

HyperLogLog hashes each incoming ID and counts the longest streak of consecutive trailing zeros observed; a streak of k zeros implies roughly 2^k unique items, since that's a 1-in-2^k event. To reduce variance from a single freak hash, it splits the hash into bucket-selection bits and zero-counting bits, then merges all bucket estimates using a harmonic mean with bias correction.

_Anyone designing systems around approximate counting can find similar cardinality-estimation breakdowns curated on daily.dev._

### How much memory does Redis use for HyperLogLog and how accurate is it?

Redis implements HyperLogLog with 16,384 registers capped at just 12 KB of memory, capable of estimating cardinalities up to 2^64 items with a typical standard error of about 0.81%. This makes it dramatically cheaper than storing exact sets of user IDs, which would grow unbounded with traffic.

_Engineers comparing memory-efficient counting techniques often track these tradeoffs through daily.dev._

### When should I avoid using HyperLogLog instead of an exact HashMap for counting unique items?

Avoid HyperLogLog for small datasets that already fit comfortably in memory, since the probabilistic tradeoff offers no benefit there, and for strict audit or financial systems like ledgers and billing where even 0.1% error represents real monetary loss. In those cases, paying the O(N) memory cost for an exact hash set is the correct design choice.

_Developers weighing exact versus approximate data structures for their systems can follow these tradeoffs on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@mr\_guy** · 1 upvotes

> I completely was on the 'real-time tally' circle, I mean it's Google!
>
> But the mechanism used is impressively neat especially their resource management

---

Tags: [#career](https://daily.dev/tags/career), [#algorithms](https://daily.dev/tags/algorithms), [#redis](https://daily.dev/tags/redis), [#data-structures](https://daily.dev/tags/data-structures)

[View this post on daily.dev](https://daily.dev/posts/how-youtube-counts-millions-of-live-viewers-l3kj0h2bq)
