Meta Questions

Design the Facebook News Feed — how would you generate and serve personalized feeds at scale?

HardSystem DesignSystem Design30-35 minutes

Model Answer

The News Feed needs to aggregate posts from friends, pages, and groups, rank them by relevance, and serve them with sub-second latency to billions of users. Architecture: 1. Data Model: Posts table (author, content, media, timestamp), Social Graph (friend relationships, follows, group memberships), Engagement signals (likes, comments, shares, view duration). 2. Feed Generation — Fan-out approaches: - Fan-out on Write: When a user posts, push the post to all followers' feed caches. Pro: fast reads. Con: expensive writes for users with many followers (celebrity problem). - Fan-out on Read: When a user requests their feed, pull posts from all their connections at read time. Pro: cheap writes. Con: slow reads. - Hybrid: Fan-out on write for regular users, fan-out on read for users with 10k+ followers. This is what Facebook does. 3. Ranking: ML ranking model scores each candidate post. Features include: post age, author relationship strength, content type preference, engagement velocity, previous interaction patterns. The model produces a relevance score; posts are sorted by score. 4. Serving Layer: Pre-computed feeds cached in a distributed cache (Memcached/Redis). When a user opens the app, serve from cache and asynchronously refresh. Pagination via cursor-based scrolling. 5. Real-time Updates: New posts from close friends trigger a push notification to the feed service, which injects the post at the top of the cache. WebSocket for real-time feed updates when the app is open.

Common Mistakes

  • 1.Only considering fan-out on write without addressing the celebrity problem
  • 2.Serving feeds chronologically instead of ranked by relevance
  • 3.Not discussing caching strategy for frequently accessed feeds
  • 4.Ignoring the real-time aspect — users expect new posts to appear quickly

Follow-up Questions

  • How would you handle the celebrity problem (someone with 100M followers posts)?
  • How would you ensure the ranking model doesn't create filter bubbles?
  • How would you implement the 'Most Recent' vs 'Top Posts' toggle?