Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 13

Design most-shared articles over sliding time windows

Advanced · 40 min · Data pipelines & analytics

A news reading app lets people share articles to friends and other apps. The home page has a "most shared" box with three tabs: last 5 minutes, last hour and last 24 hours. Editors watch the 5-minute tab to spot breaking stories, so it has to move quickly.

Requirements

  • Record a share event for an article from a signed-in user.
  • Return the top 10 articles by share count for each of three sliding windows: 5 minutes, 1 hour and 24 hours.
  • Count a given user sharing the same article at most once per 24 hours.
  • Lists update as shares happen; an article falls out of a window as its shares age past the window.

Constraints and assumptions

  • 10,000 shares per second on average, 50,000 per second at peak.
  • About 10 million distinct articles are shared in a day; popularity is extremely skewed.
  • The box is read about 100,000 times per second and may be up to 10 seconds stale.
  • Window edges can be approximate by a few seconds, but the top 10 must not include an article that clearly does not belong.

Out of scope for the first sketch

Personalized rankings · Spam classification models · The share delivery itself (sending to friends)

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches