Design a Top Shared Articles
Design the service behind a news site’s “Most shared” box. Every time a reader shares an article, by link, to a social network or by email, the site records a share event. The box shows the K most shared articles over three windows: the last 24 hours, the last hour and the last 5 minutes. Editors and partner apps read the same lists through an API.
The site records 500 million shares a day, with peaks of 30,000 a second and spikes of 100,000 a second when big news breaks, often with one article taking 30% of all shares. The 5-minute list must move within seconds, all three lists must be right, not roughly right, and a restart must not wipe a day of counts. The hard part is counting in sliding windows at this rate, when one article can be a large share of all traffic.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1How big is K?
- 2Exact or approximate counts?
- 3How fresh must the lists be?
- 4Sliding or fixed windows?
- 5What counts as a share?
- 6Global or per country and per section?
- 7Do we need old lists?
- 8Can editors remove an article?
How to spend the 45 minutes
- 5minPart 1: Requirements, windows, exact vs approximate
- 5minPart 2: Estimates: rate, skew, state size
- 5minPart 3: API
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Deep dives: buckets, merge, hot keys, exactly once