Skip to the guide

Design top-K and trending (like YouTube's most-viewed or a top-songs chart)

AdvancedCase study12 pages

The site shows the 100 most-viewed videos of the last hour, the last day and the last 30 days, worldwide and in each country, plus what's trending: videos rising faster than usual. It's the charts board in a record shop, rewritten every few minutes from every till in the country.

It's also asked as "design top K heavy hitters", "top songs of the hour" or "trending hashtags". Spotify publishes daily and weekly top-song charts per country, and YouTube Charts ranks music videos per country; YouTube retired its general Trending page in July 2025 in favour of category charts. A top-songs chart is this design with plays for views. The move is taught in Top-K and leaderboards and the windows in Real-time aggregation. Interviewers like it because the obvious answer, a Redis sorted set, fails in a way that has nothing to do with speed. Its closest case study is Search autocomplete, a top ten per prefix rebuilt from a log.

Below is a full mock interview following the seven steps of the framework. You're the candidate: at each Guess before you read on, stop and answer first.

Step 1 · Clarify the features and cut the scope

Minutes 0–5 · How this step works

Interviewer: Design the most-viewed videos chart for our video site.

You: A few questions first. Over which windows: today since midnight, or the last 24 hours rolling?

Interviewer: Rolling: the last hour, the last 24 hours and the last 30 days.

You: Worldwide only, or per country? And how many places?

Interviewer: Worldwide and each of about 200 countries. A top 100 each.

You: How fresh, and how exact? Is a video one place off near the bottom acceptable?

Interviewer: The hour and day lists within a few minutes, the month by the next morning. Close is fine, but a video that's huge everywhere must never be missing.

You: Is trending the same list?

Interviewer: No: trending is what's rising compared with its usual rate, worldwide and per country.

You: Then I'll cover top 100 lists for the hour, day and 30 days, worldwide and per country, trending in the same places, and removing a video that's taken down. Out: per-category lists, personal recommendations, and the exact view count on each video's page, which the view counter owns. OK?

Interviewer: Good.