KatInterview

Building a Live Hashtag Popularity Ranking Service

System DesignModel answer
MediumModel answerSystem Designstream-processingdistributed-systemsranking

Last updated

Design a backend that ingests social media posts at scale, computes time-sensitive popularity scores for hashtags, and serves a constantly updated list of what's trending.

You're building a service that identifies and surfaces currently popular hashtags from a high-volume social media platform. Users create posts that may include hashtags, and your system must continuously determine which hashtags are gaining traction right now and expose them through an API.

The core challenge is balancing three qualities in your ranking:

  • Recency — surface hashtags while the underlying activity is still happening. A hashtag surge should appear in your results within roughly 60 seconds. Your system looks at activity from the past 24 hours, with recent activity weighted more heavily.
  • Reach — prioritize hashtags that are reaching a broad audience, not just being repeated by a small group of highly active users.
  • Emergence — highlight hashtags that represent something new or unusual, not topics that consistently generate steady background activity.

Design how posts enter your system, how you calculate a ranking score incorporating these three factors, and how you store and deliver the ranked list to clients at scale.

Scale Parameters

Use these numbers to inform your design; you'd clarify them in a real conversation.

  • Post volume: several billion per day, translating to roughly 50,000–80,000 posts/second on average, with spikes reaching 3–5× baseline during major events. Around 15% of posts include hashtags, averaging 2 per post, yielding approximately 15,000–40,000 hashtag mentions/second in normal conditions.
  • Distinct hashtags in a 24-hour window: tens of millions exist, but most are rare. Only thousands are realistic contenders for trending status at any given moment.
  • Latency target: when a hashtag starts surging, it should appear in the trending list within ~60 seconds (99th percentile).
  • Query load: the trending list (global or segmented by geography/language) is requested at very high rates with a target response time under 100ms.
  • Consistency: the list can be eventually consistent and approximate — exact precision isn't required.

Questions You Should Explore

  • Does the service provide a single global list, or do you need per-region or per-language lists (which multiplies the aggregation work)?
  • How do you measure "reach" — by counting unique post authors, unique viewers, or raw post volume? This choice affects what data structures you need.
  • Are exact counts required, or can you use probabilistic approximations for speed and memory efficiency?
  • What's the ratio of writes (hashtag events) to reads (API queries)?
  • Should the design account for spam or coordinated manipulation (which affects how you measure both reach and emergence)?
  • How should hashtags be normalized — handling case differences, special characters, or near-duplicates like #WorldCup versus #World_Cup?

Part 1 — Ingestion Architecture

Outline the complete data flow from post creation to a queryable trending list. Identify the main system components, the streaming infrastructure, how you partition or shard the work, and a rough calculation of event rates and per-hashtag memory requirements.

Part 2 — Scoring Algorithm

Define a concrete numerical score for each hashtag that captures recency, reach, and emergence, updated at least every minute over the 24-hour observation window. Explain how each of the three required properties is measured and how they combine into a single value you can rank by.

Additional Questions for Scoring

  • What reference period defines "before" for emergence detection — recent hours, the same time period on previous days, or a long-term average? This affects whether a hashtag that trends every weekend should be surfaced each time.
  • Should scores be regionally segmented so a locally surging topic isn't hidden by global volume?

Part 3 — Storage, API, and Reliability

Describe how computed scores become a top-K list delivered through your API within the latency budget, and how the system handles failures, delayed or out-of-order events, and potential abuse.

Hints

Hint 1

Break the problem into a streaming pipeline: ingestion → aggregation → scoring → serving. Each stage has different scaling characteristics.

Hint 2

Use time-bucketed counters and probabilistic data structures (HyperLogLog for unique authors, Count-Min Sketch for the long tail) to keep memory manageable across millions of hashtags.

Hint 3

The scoring function needs exponential time decay for recency, a measure of distinct authors for reach, and a comparison against historical baseline for emergence. Combine them multiplicatively so steady high-volume hashtags don't dominate.