KatInterview

Rank Trending Content Across a Multi-Tenant Platform

System DesignModel answer
MediumModel answerSystem Designstreamingaggregationcaching

Last updated

Design a low-latency system that returns the top-N pieces of content per workspace, ranked by a weighted engagement score, over rolling time windows.

Rank Trending Content Across a Multi-Tenant Platform

Your platform hosts a collaborative content workspace — think wikis, documents, or blog posts — used by hundreds of thousands of teams. The product team wants to add a "Trending" feed that surfaces the most engaging content within a given workspace over recent time periods.

What you need to design

A backend system that answers the question: which N pieces of content have been most engaging in this workspace over the last 24 hours, 7 days, or 30 days?

Requirements

Functional

  • Accept a workspace ID, a time window (24h / 7d / 30d), and a value of N (up to 100) and return the top-N content items for that window.
  • "Top" should be based on a configurable engagement metric — views, likes, comments, or a weighted combination.
  • Results must respect content visibility rules: a requester should never see items they do not have permission to access.

Non-functional

  • Read latency: p99 under 100 ms.
  • Write volume: the platform generates hundreds of millions of view events per day, with spiky peaks.
  • Freshness: results can be a few minutes stale; real-time accuracy is not required.
  • Correctness: handle duplicate events (e.g., a user refreshing a page) and late-arriving events.

What your answer should cover

  1. How you define and compute the engagement score.
  2. The event ingestion pipeline and how you handle write volume.
  3. Storage layer choices and schema design.
  4. How you precompute or materialize top-N results efficiently.
  5. The read path, including caching and permission filtering.
  6. Deduplication, late events, and how you'd recover from data quality issues.
  7. API design.

Start by stating your assumptions and scale estimates before diving into the design.

Hints

Hint 1

Before designing anything, nail down what 'top' means. Raw view counts are easy to game — think about what a more robust signal looks like, and how storing raw counts separately from a derived score gives you flexibility later.

Hint 2

The workload is extremely write-heavy but reads are repetitive and can tolerate a few minutes of staleness. That asymmetry should drive your architecture: consider precomputing results and caching aggressively rather than querying on every request.

Hint 3

Unique-viewer counts across multiple time buckets can't simply be summed — you'll double-count users who appeared in more than one bucket. Think about what probabilistic data structure solves this efficiently at scale.