Layer 3 · Go deeper · 12 min
Go deeper
Size it, build it, then make the calls an interviewer will push you on.
Back of the envelope
Size it up
Tap through each step of the arithmetic.
How uneven is traffic across a million sites?
How much ingest bandwidth, and how many collector pods?
How much disk do 13 months of events take?
How much does a 30-day unique-visitors chart read for the biggest site?
Build-up · 5 steps
Build the high-level design
One functional requirement at a time, ending with a service that works for a few thousand sites in one region.
Step 1 of 5
Track a site with one tag
The page waits only for a 202: the collector appends to Kafka and everything slow happens later. Enrichers parse the user agent and drop bots; a loader batches inserts, since each insert makes a part to merge.
6 interview moments
You’re the candidate
The interviewer pushes on the hard parts. Pick an approach and see how it holds up.
Deep dive 1 of 6
Interviewer
“The events that matter most happen just as the visitor leaves. How does the script send them without slowing the page?”
Your move. Pick an approach:
Deep dive 2 of 6
Interviewer
“The dashboard needs unique visitors, and the requirements say no cookies by default. How do you recognise a returning browser?”
Your move. Pick an approach:
Deep dive 3 of 6
Interviewer
“An owner picks any date range and any set of pages. How do you count unique visitors across them?”
A hundred visitors at 09:00 and 120 at 10:00 might be 130 people or 220.
Your move. Pick an approach:
Deep dive 4 of 6
Interviewer
“50B events a month, and every dashboard panel must answer in under a second, for the biggest site too. How do you store them?”
Your move. Pick an approach:
Deep dive 5 of 6
Interviewer
“Bounce rate, visit duration and entry pages all need sessions: no gap over 30 minutes. Where do you build them?”
Your move. Pick an approach:
Deep dive 6 of 6
Interviewer
“Election night: a news site jumps from 300 to 30,000 events a second for hours. How do you shard the store?”
Kafka keyed by site and visitor already spreads it over all 64 partitions. The store and its queries are the pressure points.
Your move. Pick an approach:
Build-up · 8 steps
Follow one pageview through the final design
The page waits only for a 202. Everything after it is asynchronous and can fall behind and catch up.
Step 1 of 8
Collect
A beacon is never retried, so the collector is the durability boundary: in-memory checks, hash IP, user agent and site with today’s salt, drop the IP, reply 202, append to Kafka keyed by site and visitor.