Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 49

Design a live viewer count for a page

Intermediate · 30 min · Real-time delivery

A product page, article or listing shows a small badge: "1,240 people are viewing this". The number should feel alive: it rises as people arrive and falls as they leave, including people who just close their laptop or lose signal without ever telling the server.

Requirements

  • Show an approximate count of people currently viewing a page.
  • The count drops when viewers leave, including when they disappear without any goodbye signal.
  • While the page is open, the displayed count refreshes about every 15 seconds.
  • A person with the same page open in several tabs counts once.

Constraints and assumptions

  • 50 million concurrent viewers spread across 20 million pages; most pages have 0 to 5 viewers, the most popular has 3 million.
  • A viewer who leaves should stop counting within 60 seconds.
  • Counts above 1,000 may be off by 2% and are shown rounded; counts under 100 should be exact or off by one.
  • Nothing about who is viewing is shown or stored beyond what counting needs.

Out of scope for the first sketch

Showing who the viewers are · Historical traffic analytics · Pushing updates over a persistent connection (polling is fine to start)

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches