Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 20

Design a website analytics pipeline and dashboard

Advanced · 45 min · Data pipelines & analytics

Site owners paste a small script into their pages and then open a dashboard to see how many people visited, which pages they read, where they came from and how long they stayed. A "right now" panel shows how many visitors are on the site at this moment.

Requirements

  • Collect page views and custom events from a JavaScript snippet without slowing the page.
  • Group a visitor's events into sessions that end after 30 minutes of inactivity.
  • Show page views, unique visitors, sessions, bounce rate and average session length over any date range, broken down by page, referrer, country and device, with filters.
  • Show visitors active in the last 5 minutes, updated every few seconds.

Constraints and assumptions

  • 200,000 sites; 50,000 events per second on average, 300,000 at peak. The largest site sends 30% of all events.
  • A visitor is identified by a random first-party ID stored in the browser; some browsers clear it daily.
  • Dashboard reports for the last 30 days should load in under 2 seconds at p95.
  • Realtime panel within 1 minute of the event; daily reports may be corrected for up to 24 hours.
  • Unique visitor counts within 2% are acceptable. Raw events are kept for 13 months, aggregates for 5 years.

Out of scope for the first sketch

Ad attribution and conversion modeling · Per-user journey and funnel analysis · Billing and account management

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches