InterviewLegend

Design Trending Topics

Alex Chen44 min read169 real interview reports

Trending topics looks like the easy cousin of the timeline: just count hashtags and show the biggest ones. The trouble is hiding in the word "count." The timeline moves a known post to a known set of followers. Trends has to watch an unbounded stream of terms it has never seen before and answer, continuously, which handful are surging right now. Two things make that hard: the volume is enormous and never pauses, so the counting has to happen in one streaming pass. And the number of distinct terms is huge, in the tens of millions an hour, so you cannot afford a running tally for each one.

The X angle
X Trends is the canonical top-K streaming problem, and a strong answer is judged on one move: realizing you must not try to count everything exactly. Trends are scoped to a location, chosen historically by a "Where On Earth" id so a user in London and a user in São Paulo see different lists. Each entry shows an approximate post volume, which tells you the exact count was never the point. And the list refreshes on the order of minutes rather than seconds, which buys you room to approximate. Candidate reports on this shape describe the same arc every time. A generic answer says "increment a counter in Redis per hashtag" and gets walked straight into the cardinality wall. The differentiated answer names approximate counting, a Count-Min Sketch for volumes and a heavy-hitters summary for the top set, and treats exactness as something you deliberately trade away.
What's inside
  • 1 diagram
  • 5 sections
  • about 44 min

Premium lessonX (Twitter) interview guide

These took digging.

What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.

100 companies. Checked every month.

Unlock all 100 companies

$49 a year · less than $1 a week · Cancel anytime

Had your X (Twitter) interview?Tell us what they asked. Reviewed before it goes in, never with your name.
X (Twitter) interview guide

Know what X (Twitter) asks before you walk in.

19 coding · 5 system design · 20 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.