Top Ten Right Now
Design the service behind a "trending now" widget: the ten most searched terms right now over the last 5 minutes, the last hour, and the last 24 hours, for a global search engine.
Requirements
Functional: publish a ranked top ten per window; expose one global list plus a per country list; show the count next to each term and how its rank moved since the previous publish; keep 7 days of published lists for debugging.
Non-functional: the 5 minute list may lag real time by at most 10 seconds; ranking must be correct for the head, meaning two terms whose volumes differ by more than 1 percent are never swapped, and displayed counts are within 1 percent of truth; read p99 under 100 ms; the pipeline must survive an aggregator node loss without republishing a wrong list.
Scale
400M daily active users, about 6 searches each, so 2.4B search events per day: roughly 28k events/s average and 83k/s at peak. An event is about 120 bytes on the wire (normalized term, event time, country, device class, salted user hash). Roughly 250M distinct terms per day, dominated by a near unique long tail. The widget renders about 50k times/s, but there are only 3 windows times 250 countries of distinct answers. Retain raw events 7 days.
Out of scope
Search itself (indexing, ranking, autocomplete), fighting query spam in the search corpus, personalization of the list per user, and the front end.
Sign in to answer questions and track your progress
Sign In