Skip to content
SD-22 · System design

Design a Top K Rankings

Asked at Mid level45 minutes
Our answers stay hidden until you reveal them.

Design the service behind an app store’s top charts or a shop’s bestseller lists. Every download or purchase counts towards an item’s rank, and readers see the top 200 items for a chart, such as top free, top paid or top grossing, filtered by category and country, over the last hour, day or week.

The store sees 1 billion ranking events a day across 5 million items, with launch-day spikes far above the average, and readers open charts 400 million times a day. The hard parts are counting a fast, very uneven stream without a hot row for every viral app, keeping about 81,000 lists fresh within a minute, and stopping bot farms from buying a place in the chart, since a top spot is worth real money.

Good questions to ask first

Decide what you would assume for each before you look at ours.

  1. 1What counts towards a rank?
  2. 2How fresh must a chart be?
  3. 3Which time windows?
  4. 4How many lists?
  5. 5Must counts be exact?
  6. 6Where do events come from?
  7. 7Can one user boost an app by installing it again and again?
  8. 8Do developers need their rank history?

How to spend the 45 minutes

  1. 5minPart 1: Requirements and scope
  2. 5minPart 2: Estimates
  3. 5minPart 3: API
  4. 15minPart 4: Architecture, stage by stage
  5. 15minPart 5: Deep dives and trade-offs
Sketch your own design: boxes, arrows and the numbers that matter. Then compare it with ours.Break it in the labVisual walkthrough