#49EasyReal-Time & Stream Processing

Design a Feature to Show the Number of Users Viewing a Page

ASKED IN INTERVIEWS AT:Booking.com

EXECUTIVE SUMMARY & PROBLEM STATEMENT

Design Booking.com's live viewer counter ('14 people are currently looking at this hotel') using heartbeat beacons and approximate cardinality counters.

SCALE ESTIMATION & TRAFFIC ENVELOPE

DAILY ACTIVE USERS / TPS20 Million concurrent browsing sessions, heartbeats every 20 seconds
READ / WRITE TRAFFIC RATIO1:1 write heartbeat to read count
5-YEAR STORAGE CAPACITYRedis HyperLogLog keys: 1.5 KB per hotel listing * 1M hotels ~ 1.5 GB RAM

FUNCTIONAL REQUIREMENTS

  • [1]Display real-time count of active users currently viewing a hotel listing
  • [2]Keep count accurate as users navigate away or close tabs

NON-FUNCTIONAL REQUIREMENTS

  • •Minimal client battery/network impact
  • •Response latency < 100ms
  • •Tolerate occasional missed heartbeats gracefully

CORE ARCHITECTURAL COMPONENTS

Client Navigator.sendBeacon() hook
Lightweight Edge Heartbeat Collector
Redis HyperLogLog Sliding Window
Viewer Count Query API

DATA SCHEMA & PERSISTENCE

Redis Key: `viewers:{hotel_id}:{minute}` -> HyperLogLog or Sorted Set

DISTRIBUTED TRADE-OFFS & FAILURE MODES

  • ⟡HyperLogLog provides 98.5% accurate viewer counts with constant 1.5 KB RAM per page, ideal for social proof urgency indicators.