KatInterview

Design a Trending Content Feed with Near-Real-Time Ranking

System DesignModel answer
HardModel answerSystem Designstreamingrankingcaching

Last updated

Architect a system that ranks articles by engagement velocity with 1–2 minute freshness, covering ingestion, streaming aggregation, storage tiers, and cheap high-QPS serving.

You are asked to design a backend that shows readers which articles are trending right now, at very large scale.

Scope to pin down with the interviewer first:

  • Read APIs: fetch a trending list for a scope (worldwide, country, language), optionally filtered by category; optional per-user re-ranking on top of a global list; cursor-based pagination that must not duplicate or skip items while a reader pages through.
  • "Personalized" vs. "global": whether the base list is shared and lightly re-ranked per user, or fully user-specific.
  • Write path: client- and server-generated engagement events (impressions, opens, time-on-page, shares), plus editorial removal of an article that must hide it within seconds.
  • SLAs: how quickly an event must influence the ranking (e.g., 1–2 minutes), read latency target (e.g., P99 under 100 ms), availability target, and graceful degradation of ingestion.

State your assumptions numerically: daily active users, events per user per day, read requests per user per day, catalog size (total and new articles per day), peak-to-average ratios, regions and locales.

Deliver:

  1. An explicit definition of "trending" that distinguishes it from "merely popular," including how recency is weighted and how per-event weights are chosen.
  2. The ingestion architecture and event schema, with an idempotency story and anti-abuse/dedup rules.
  3. The streaming and batch compute plan, including how sliding windows and decayed counts are maintained, and how a two-stage top-N is computed per dimension.
  4. Storage tiers (hot/warm/cold), what lives in each, retention, and partitioning/indexing choices.
  5. Caching, snapshot publishing, and cache invalidation.
  6. Consistency model, backfill/reprocessing, fault tolerance, sharding, and rough capacity estimates.

Justify each technology choice against alternatives and call out the trade-offs you are accepting.

Hints

Hint 1

Separate the problem into a heavy write path, a heavy read path, and a tiny piece of data that is actually served — the served lists are small precomputed snapshots, so spend your design effort on aggregation, not on request-time ranking.

Hint 2

Use forward decay: accumulate sum(w_i * e^(lambda * t_i)) instead of decayed scores, so each event is one addition; ranking order is preserved because every item shares the same global decay factor at read time.

Hint 3

A single heavily-promoted article can flood one stream partition; partition by article id for local state, then merge partial top-N heaps in a second stage — any item in the global top-N must be in some partition's local top-N.

Hint 4

Make the served snapshot immutable and versioned, then swap a single pointer key atomically, so readers never see a half-built list.