Skip to content
SD-20 · Back to the write-up

Design a Web Analytics Pipeline

Collect into a log, drop bots and pre-aggregate in a stream with sketches, keep raw events in a columnar store, and let dashboards read the small rollups.

Follow a request

Browsers
Ingest
Processing
Storage
VisitorTag on the page
Site ownerDashboard
Script CDNtag.js
CollectorsStateless
Query APIRollups first
Event logBy site, 7 days
Stream processorBots, rollups, HLL
Batch recomputeNightly
Raw eventsColumnar
RollupsMinute, hour, day
1visitor → cdn · GET tag.jsThe page loads our 2 KB script from the nearest edge, asynchronously, so the page never waits for it.1 / 7

The numbers, at a glance

Of every 10 hits……about 3 are bots
3 bots, dropped7 counted
Raw events pile up700 GB a day, kept 13 months
Rollups are tinyHourly rollups vs raw events per day
Daily rollups are 24× smaller again, so a year of dashboards reads kilobytes.

A page view, in order

The visitor’s part ends at 204; everything after it is off the page’s path.

Browser
Collector
Event log
Stream
Rollups
Raw store
1 sendBeacon /collect
2 append (site partition)
3 ack, 2 of 3 copies
4 204
5 event stream
6 upsert minute rollup
7 batch of raw events
RequestResponseAsync, does not block

Where dashboard numbers come from

The decision this question is really about.

Scan raw events
Too slow alone
widget
scan billions of rows
seconds per chart
+ Any question, exact.− 2,000 scans a second.
Only rollups
Too rigid
event
+1 counter
raw thrown away
+ Tiny and fast.− No raw data to fix or explore.
Rollups + raw columnar
Our pick
event → log
stream rollups + HLLraw columnar
nightly recompute
+ Fast reports, raw kept for the rest.− Two paths to keep in step.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 1,000 events/sMake it work
BrowserOwner
App server
SQL table
One server inserts rows; dashboards run GROUP BY.
Stage 2 · ≈ 100,000 events/sAbsorb the firehose
BrowserScript CDN
Collectors
Event logStream loader
Columnar store
Collectors append to a log; batches load a columnar store.
Stage 3 · ≈ 400,000 events/sPre-aggregate
BrowserScript CDN
Collectors
Event logStream rollups + HLL
Columnar storeRollup store
Stream rollups with sketches; dashboards read rollups.
Stage 4 · 400,000 events/s + late dataMake it right
BrowserScript CDN
Collectors
Event logStream rollups + HLLBatch recompute
Columnar storeRollup store
Nightly recompute with late events, bot rules and deletes.
Was this walkthrough useful?Your vote tells us what to improve next.