Preparing your design workspace

Loading the problem and your latest saved attempt…

Design an Authenticated Page Presence Counter

Design a live distinct-user count for authenticated viewers of a page.

Problem statement

For this exercise, assume an authenticated user counts once for a page while at least one of that user's tabs or devices maintains an active viewing session. Clients send heartbeats, and a session expires after 60 seconds without a heartbeat or an explicit leave.

The page displays an approximate live distinct-user count within five seconds; transient overcount or undercount during the expiry window is acceptable, but identity and page membership must remain private. Historical analytics and showing individual viewer identities are outside scope.

As part of the design, compare read fan-out and write fan-out for computing and delivering the live count, and choose and defend push, pull, or a hybrid for ordinary pages and for a hot page with 500,000 concurrent viewers.

What to build

  1. An authenticated client can start or refresh a viewing session for one page without counting the same user more than once.
  2. A client can leave explicitly, and abandoned sessions stop contributing after the bounded heartbeat timeout.
  3. Authorized page viewers can receive an approximate distinct-user count refreshed within five seconds.

At scale

  • For this exercise, assume 5 million concurrent sessions across 500,000 pages, with one page occasionally reaching 500,000 concurrent users.
  • For this exercise, clients heartbeat every 20 seconds and a missed session expires after 60 seconds.
  • For this exercise, count updates should reach connected viewers within five seconds, and temporary error within one percent is acceptable during churn.
  • For this exercise, the service must not expose viewer identities and should recover counts after a process or shard failure.