Design Top-K Trending Topics

Trending topics inspired by Twitter/X Trends and YouTube Trending: hashtag events on a partitioned stream, windowed counting with a count-min sketch and heavy-hitter heaps, trends ranked by velocity against a baseline, a precomputed top 50 per region in a cache, a replayable raw-event archive and bot filtering. A teaching design.

Functional requirements

  • Every post and search with a hashtag is recorded as an event.
  • Users can see the top trending topics for their region.
  • Trends reflect what is rising fast now, not what is always popular.
  • Trends refresh at least every minute.
  • Activity from bot accounts does not push a topic into trends.
  • Counts can be rebuilt from raw events after a bug.

Non-functional requirements

  • Trending tab latency: p99 < 200ms.
  • Freshness: a topic that starts rising appears in trends within 1 minute.
  • Posting is never slowed down by counting.
  • Scale: 50M daily users, 5K requests/s at peak, mostly events.
  • Availability: 99.9%; stale trends are acceptable, errors are not.
  • Approximate counts are acceptable for ranking.

How the design evolves

Stage 1: One Counter Row per Hashtag

See why a database row per hashtag breaks the moment one tag goes viral.

What was missing: Nothing yet.

Why that's risky: A viral hashtag sends thousands of updates per second to the same row, and they queue behind its lock. Sorting every hashtag on each read gets slower as the table grows.

What gets added: One server that adds one to a hashtag's row on every event, and sorts every row by count when someone opens the trending tab.

Trade-offs: Exact counts and one place to look, paid for with a write on every event and a full sort on every read.

Stage 2: Events Through a Stream, Counted in Batches

Take counting off the request path and stop hot rows.

What was missing: Every event was a database write, and a viral hashtag turned into one hot row.

Why that's risky: The trending tab still sums an hour of minute rows and sorts every hashtag on each read.

What gets added: An ingest service that only appends events to a stream partitioned by hashtag, counter workers that add up each minute in memory and write one row per hashtag per minute, and a trends service behind a load balancer.

Trade-offs: Counts lag by up to a minute, which nobody notices on a trending list.

Stage 3: Sliding Windows and a Precomputed Top 50

Rank by how fast a topic is rising, and serve the answer instead of computing it per read.

What was missing: Trends were computed from scratch on every read, and the most-used hashtags (good morning, every day) always won.

Why that's risky: Raw events live only in the stream. A counting bug or a lost partition can't be repaired by recounting.

What gets added: A count-min sketch and a heap of heavy hitters in each counter, a ranker that scores tags every 30 seconds by how fast they rise over a sliding window against their usual baseline, and the top 50 per region written to a trends store and a cache.

Trade-offs: A count-min sketch can over-count slightly in exchange for fixed memory. That's fine for ranking, not for billing.

Stage 4: Replayable Archive and Bot Filtering

Make counts repairable, and stop fake accounts manufacturing a trend.

What was missing: No way to recount after a bug, and a few thousand bot accounts could push any tag to the top.

Why that's risky: One entry point and no limit on how fast a single account or IP can post events.

What gets added: An archiver that writes every raw event to hourly files in object storage, and counters that skip flagged bot accounts and count each account once per hashtag per window.

Trade-offs: Archiving raw events costs storage, but makes every count reproducible.

Stage 5: Rate Limits, Redundancy and Monitoring

Survive a breaking-news spike and a bot flood, and see trouble before users do.

What was missing: One load balancer, no per-account limits, and no view of stream lag or freshness.

Why that's risky: Remaining risk is low at this scale. A second region would cover a full regional outage.

What gets added: A redundant load balancer, a rate limiter per account and IP, extra ingest, trends and counter instances, a replicated counts store, and monitoring of stream lag, counter throughput and how old the current trends are.

Trade-offs: Trends are up to 30 seconds old by design, the price of serving them from memory.

PRISM
System Design Interview
Round 1 of 4 · Architecture Design · 60:00 remaining
PRISM logo
AI Interview
Interview Prep
Interview Challenges
Build & Stress Test NEW
System Architectures
Design & Fix NEW
Interactive Roadmap System Design Guides
Notifications
  • No new notifications
Feedback
Signed in
Send feedback
Phase
Build & Stress Test
Phase 01: Thinking in Systems
Upcoming

Components

User
CDN
Load Balancer
Server
Cache
Database
Blob Storage
Search Index
Queue
Worker
Rate Limiter
Service
API Gateway
Reverse Proxy
WebSocket Server
Third-party API

Inspector

Notes
Use clear names so your design intent is easy to understand.
Good
Name by business meaning
"Order API", "Restaurant Service"
Avoid
Generic names = zero signal
"Server 1", "API", "Queue"
A short description for each component makes feedback much better.
100%
Start by identifying:
  • Users & entry points
  • APIs & services
  • Databases & storage
  • Traffic flow & scale

Round 1 of 4 Architecture Design

Run a simulation to see results.

Time Remaining
60:00
System Design Interview

What are the core functional requirements?
What are the key non-functional constraints?

Questions

Start Evaluation to unlock questions.

EVALUATE MODE

Test yourself like it's the real thing.

A structured 4-module evaluation that mirrors how top companies assess system design candidates.

Architecture Design
Draw your system on the canvas. Define components, connections, and data flow.
FR & NFR Requirements
Answer functional and non-functional requirement questions about your design.
MCQ Round
Multiple choice questions testing your depth on the chosen system.
Tradeoff Analysis
Justify your design decisions and defend your architectural tradeoffs.
AI Report Generated
Choose a Problem
No problem selected
  • 30 min
  • 45 min
  • 60 min
Round 2 of 4
MCQ Round
Answer multiple-choice questions based on your design.

Exit Interview?

You're in the middle of an interview session. Leaving now will end your current attempt.

Your progress will be saved.

Open a saved design

Select a design to load into the canvas.

My Evaluations

Your past evaluation sessions

Here’s a simple request flow that follows the expected layer order.

External User
→
Edge CDN → API Gateway → Load Balancer
→
Compute App Servers / Services
→
DataAccess Cache
→
Storage Database / Search Index
→
Async Queue → Worker

Tip: keep arrows moving forward through layers (Edge → Compute → Storage). Avoid sending storage back to compute.

Evaluation Instructions

Read the rules carefully before starting. The test auto-submits on refresh.

Before you start

  • Build your architecture on the canvas. The timer starts when you click Start Evaluation.
  • Don't forget to answer Functional Requirement and Non Functional Requirements.
  • When satisfied with your design, click Next to lock it and view the questions.
  • Please answer final step questions to complete the evaluation.

Dos

  • Do read each question carefully before answering.
  • Do include required components to maximize component coverage.
  • Do save a copy of your design if you want to keep it before submission.

Don'ts

  • Don't refresh or close the tab during an active evaluation — this will auto-submit your answers.
  • Don't switch app modes or open another tab while the evaluation is running.
  • Don't attempt to edit the design after clicking Next; the workspace will be locked.

All the best!!

Confirm

Input

Notice

Evaluation Report

Evaluation Complete

Generating Your Report

Hang tight — our AI is evaluating your design…

Did you know?

Loading…

Share feedback

Tell us what worked well and what we can improve.

Let's personalize this

Answer a couple of quick questions so we can tailor your journey and missions.

Your welcome gift: of Full PRISM Access

You can change these answers from Mission Control until your missions are done.

Your personalized missions are ready

We tailored these first steps based on your answers.

    PRISM Welcome Gift

    This is a personal welcome gift from PRISM.

    Congratulations.

    You explored PRISM.

    You earned Apprentice.

    As a welcome gift, unlock Full PRISM Access for the configured trial duration.

    This starts Trial. Trial timer begins only after you activate this gift.

    Welcome to PRISM

    We've prepared a personalized Apprentice Journey based on your goals and experience.

    This journey introduces you to the capabilities of PRISM that are most relevant to you.

    Complete all 5 missions to earn your Apprentice title. 5 MISSIONS

    PRISM Surprise Offer

    Complete your Apprentice Journey to unlock a special gift from PRISM.

    • No payment required
    • No credit card required
    • Just complete the journey
    MISSION CONTROL
    0 / 8 missions complete
    NEXT UP Continue your missions
    View full roadmap →
    Mission Complete 0 / 8 Completed Next: Keep going
    SYSTEM BRIEF

    System Constraints

    What the system must do — every item is a user-facing behaviour your architecture must support.

      ↑ Engineering Constraints

      These are the failure modes you must design against — latency SLAs, durability targets, traffic ceilings.

        ⇆ Architecture Constraints

        Core Concepts to Master

        Your Journey
        PHASE – –
        0 / 0 0%
        0
        Mock Interview Checklist

        Pick a topic to start

        Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.

        Phase Mastered

        You've conquered this phase. These are the skills you now own:

          +500 XP

          Company Interview Paths

          Progress Summary