InterviewLegend

Design a Top-K and Leaderboard System

Signature problem
Alex Chen55 min readAdded 1,382 real interview reports

A Top-K system counts events per item and keeps a ranked list of the K biggest, for example the 10 or 100 most-played songs. On one machine that's a hash map and a heap. It gets hard at a few hundred thousand events a second, and harder again when the window slides, because counts have to go down as old plays age out. The same machinery sits under a family of prompts. Top URLs over the last hour, day and week is this problem with a far bigger set of keys. A gaming leaderboard ranks scores instead of counts and adds "what's my rank?". A live viewer counter is one item with an enormous count. This lesson builds the song chart end to end, then takes the URL, leaderboard and live counter versions as deep dives.

The Microsoft angle
This shape reaches Microsoft candidates under many names: top K songs over 7 days, most visited items per hour, day and week, a Top-K URL system, a gaming leaderboard, an Xbox view count, top stock gainers. Most reports come from SDE II loops. Nearly all come down to counting events per item over a window and ranking the result.

MicrosoftPremium lesson · System design round

The Microsoft design, worked end to end.

  1. The API and data modelSystem design · Signature problem
  2. The design, drawn out2 diagrams
  3. 6 deep divesWith the tradeoffs
Get the Microsoft questions

$49 a year · all 107 companies · instant access

1,382 Microsoft interview reports · guide updated

Microsoft interview guide

Know what Microsoft asks before you walk in.

21 coding · 9 system design · 24 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

Had your Microsoft interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.