Design a Live Viewer Count
Understanding the Problem
👀 What is a live viewer count? It's the "48.2M watching now" badge on a live stream. It counts how many people are watching at this moment, not how many have ever tuned in, and it updates every few seconds. On a big sports platform, a cricket or football final can draw tens of millions of concurrent viewers to a single stream, so the system has to count a huge, constantly changing set of people, and then show the result to all of them.
You might get this as "show concurrent viewers of a live match," "count unique concurrent users on a streaming platform," or "near-real-time viewer counts for every live stream." They're the same problem. The interesting parts are knowing when someone has left (they rarely tell you), counting a person once even if they have the match open on their phone and their TV, and the surprising fact that showing the count is harder than computing it.
Functional Requirements
We'll agree with our interviewer that video delivery is someone else's problem. We're building the count.
Core Requirements
- Viewers should be able to see how many people are currently watching a live stream, updated every few seconds.
- A user watching on several devices or tabs should be counted once (unique concurrent users).
- Broadcasters and the operations team should be able to see the viewer count over time, including the peak.
Below the line (out of scope)
- Total unique viewers over the whole event ("120M people watched"). We'll mention how to get it cheaply.
- Viewer lists ("who's watching") and live chat. Chat comes up later only as a delivery channel.
- Detailed analytics such as watch time per user or drop-off by minute. That's an analytics pipeline that reads the same events.
Non-Functional Requirements
Ask your interviewer for the biggest single event, not just the platform total, because one huge stream is what breaks naive designs. For our design: 100M concurrent viewers across the platform at peak, with one stream reaching 50M, alongside about 1M smaller streams.
Core Requirements
- The system should update the displayed count every 5-10 seconds, and reflect departures within about a minute.
- The system should be accurate to within about 1% on big streams, and exact on small ones. A streamer with three viewers notices if it says five.
- The system should absorb join spikes (tens of millions of people arriving in the minutes before kickoff) without the count lagging or stalling.
- The system should never let a count failure affect video playback.
Below the line (out of scope)
- Strong consistency. Two viewers can see counts a few seconds apart.
- Counting viewers who aren't connected to us at all (TV broadcast, re-streams).
The math. If each player sends a heartbeat every 30 seconds, 100M viewers produce 100M / 30 ≈ 3.3M heartbeats/sec, and the big stream alone produces about 1.7M/sec. Each heartbeat is around 100 bytes, so roughly 330 MB/sec of ingest. That's a lot of small requests, but it's spread across many machines and every one of them is cheap.
Now the read side. If every viewer polls the count every 10 seconds, that's 100M / 10 = 10M requests/sec, three times the heartbeat load, and 5M/sec of it for the same number on the same stream.
Most candidates spend their time on counting. The bigger load in this problem is delivering the count: millions of clients asking for the same number every few seconds. Spot that early, because the answer (cache it at the edge or piggyback on a channel that already exists) is simple once you see it.