How a live stream counts '5.9 crore watching' (heartbeats, TTL, hot keys and local counters)
Why live-viewer counters can't just do +1 when you join and -1 when you leave, and how systems like this are built instead: heartbeats, TTL expiry, avoiding a hot key with local counters, aggregation, and an approximate number on purpose. With an interview answer.
By InternHack Team · · 5 min read · System Design
The match ends, you close the app, and the counter in the corner still counts you for a while. During the 2023 World Cup final, Disney+ Hotstar reported a peak of nearly 5.9 crore people watching at once. How does an app count that many people when no phone ever says "I'm leaving"?
A note on honesty: Hotstar, YouTube and Twitch haven't published how their viewer counters work. What follows is how systems like this are generally built, taken from public engineering write-ups on the same problem by LinkedIn (who's online right now), Google Firestore (distributed counters) and Netflix (its distributed counter).
Why +1 on join and -1 on leave doesn't work
The obvious design: when you open the stream, add one; when you close it, subtract one. The problem is that "leave" events are unreliable. Your battery dies, the app gets killed, you go into a metro tunnel, a tab is closed. None of these send a "bye". LinkedIn noted that mobile users "regularly get disconnected and reconnected haphazardly". So the minus-one never happens, and the count only grows: ghost viewers who never go home.
Sign up free to unlock the full notes
Aage ke sections free InternHack account ke saath khulte hain:
- The design in one picture
- Fix 1: heartbeat
- Fix 2: TTL (expiry)
- Fix 3: avoid the hot key with local counters
- Fix 4: aggregation
- Fix 5: approximate on purpose
- Edge cases and things you've seen
- How to answer this in an interview
- The question from the reel
Sources
- LinkedIn real-time presence platform (heartbeats, expiry, mobile disconnects): https://www.linkedin.com/blog/engineering/product-design/now-you-see-me-now-you-dont-linkedins-real-time-presence-platf
- Google Firestore distributed counters: https://firebase.google.com/docs/firestore/solutions/counters
- Netflix Distributed Counter (InfoQ summary): https://www.infoq.com/news/2024/12/netflix-distributed-counter
- YouTube Data API, concurrentViewers: https://developers.google.com/youtube/v3/docs/videos
- YouTube Help, concurrent viewers: https://support.google.com/youtube/answer/2853833
- Disney+ Hotstar WC 2023 final, nearly 5.9 crore peak: https://deccanherald.com/sports/cricket/india-aus-world-cup-final-match-creates-record-peak-viewership-of-59-cr-on-disneyhotstar-2777180 ; https://www.exchange4media.com/digital-news/india-aus-final-wc-match-peak-concurrency-touches-59-crore-131034.html
- JioHotstar IPL 2025 final, 5.5 crore peak: https://www.socialsamosa.com/industry-updates/tata-ipl-2025-highest-viewership-across-tv-digital-platforms-jiostar-9379318
- JioCinema cumulative views (Nov 2023): https://www.businesstoday.in/sports/story/india-vs-australia-t20-jiocinema-sees-massive-viewership-of-12-cr-407168-2023-11-26
- AWS on backoff and jitter: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/