System Design Problems interview question · Most asked

Design a social media news feed (like Twitter/X or Instagram).

Summary

Precompute feeds by fanning out new posts to followers' timelines in a cache (fan-out on write) for normal users, merge posts from celebrities at read time (fan-out on read), and rank the merged candidates before returning a paginated feed.

Requirements

  • Users post content and follow others
  • Home feed of followed users' posts, newest or ranked
  • Feed loads fast (< 200 ms)
  • Scale: 300M daily users, some accounts with 100M followers

Back-of-the-envelope

  • Feed reads ≫ posts (~100:1)
  • Fan-out on write for an average 200 followers is cheap; for 100M followers it's not

API

POST /api/posts                 {"text": "...", "media_ids": [...]}
GET  /api/feed?cursor=<opaque>&limit=20
POST /api/users/{id}/follow

Data Model

posts(post_id PK, author_id, body, media, created_at)          -- sharded by post_id
follows(follower_id, followee_id, created_at)                   -- both directions indexed
timeline cache: Redis list feed:{user_id} → [post_id, ...] (capped ~800)

Architecture

The post service writes posts and emits an event. Fan-out workers read the author's followers and push post IDs into each follower's timeline cache (skipping inactive users). At read time the feed service loads the cached IDs, merges recent posts from followed celebrities, hydrates posts and authors from caches, applies ranking, and returns a cursor page.

Deep Dives

  • Hybrid fan-out: push for accounts below a follower threshold, pull for celebrities
  • Ranking: candidate generation then a scoring model (engagement prediction, recency, diversity)
  • Pagination: cursors based on post IDs/scores, not offsets
  • Deletes/privacy: filter at hydration time so deleted or blocked content never shows

Scaling

  • Shard timelines by user_id
  • Only maintain timelines for active users; rebuild on demand
  • Media via CDN
  • Hydration via batched multi-get from caches

Comparison / Tradeoffs

Decision Option chosen Alternative Why
Fan-out Hybrid Pure write or pure read Fast reads without celebrity write storms
Timeline storage Redis lists of IDs Full posts in timeline Small memory; posts hydrated once
Ordering Ranked Chronological Engagement, with chronological option

Explanation

What interviewers look for

A structured approach: clarify requirements and scale, sketch the API and data model, draw the high-level architecture, then go deep on the hardest component and discuss trade-offs, bottlenecks and failure modes.

Follow-up questions

  • How do you handle a user who follows 5,000 accounts?
  • How do you insert ads?
  • How would you make the feed real-time?

More most-asked System Design Problems questions

← All System Design Problems questions