Module 12 · System Design · The questions that keep coming up · about 23 min to read
Continue where you left off ×
The top ten right now (a sketch that is small and wrong by a known amount)
Counting Clicks in Real Time · Open board
The click pipeline growing one step at a time. This lesson works inside the box that answers “which ten are hottest right now”, and then adds a second box for “how slow is the slowest 1%”.
Before you start. Counting the crowd without a register (HyperLogLog, count-min, top-k) showed that a small structure can trade a little accuracy for a lot of memory, and Hashing gave you the fixed recipe that turns any name into a number. Counting clicks in real time (ad click aggregation and top-k) cut an endless stream into one-minute slices, and Splitting the ledger (sharding) spread one stream over many machines, so that each machine sees only a share. This lesson asks the two questions 0334 did not: how often, and how slow.
The idea in 30 seconds
A top-k list is the k most frequent things in a stream, and keeping a counter for every thing grows without limit.
A count-min sketch is a grid of shared counters, 40 KB for 5 rows of 2,000, and it can be too high but never too low.
The overcount is bounded by about e divided by the row width, as a share of all events, and the top ten stay right when the gaps between ranks are larger than that.
Sketches from many machines add cell by cell into the exact grid one machine would have built.
A sliding window is the latest few one-minute grids added together, and expiring old data means dropping a grid.
A percentile like p99 cannot be averaged, and a t-digest keeps about a hundred clusters that merge instead.
Read the story
Lesson 68 of 115 in System Design
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 2010: Twitter has to explain a list The honest way: one slip for every call A grid of counters that strangers share: the count-min sketch Wrong by an amount you can state before you start Many phone banks, one wall: merging sketches Right now: the sliding window Not how often but how slow: percentile and p99 A summary that merges: the t-digest Requirements, numbered Out of scope, said out loud Targets Estimates that change the design Entities and API Storage, with the trade said plainly The design, one requirement at a time Deep dives What each level adds The follow-up: trending, not just popular Terms it explains: top-k, count-min sketch, sliding window, 99th percentile, t-digest, Common mistakes, event, minute summary, idempotent, min-heap, partition, tumbling window, watermark.
Review System Design
Mark as read Saved in this browser, and to your account when you sign in.