MongoDB

Designing a News Feed System

How Facebook and Instagram design personalized news feeds — covering fan-out on write vs read, ranking, and caching strategies.

S

srikanthtelkalapally888@gmail.com

Designing a News Feed System

A news feed aggregates and ranks posts from followed users and displays them in a personalized timeline.

Requirements

  • Display posts from followed users
  • Near real-time updates
  • Ranked by relevance/recency
  • Support 500M daily users

Two Approaches

Fan-Out on Write (Push Model)

When a user posts, immediately write to all followers' feed caches.

User A posts → Write to follower B, C, D feeds

Pros: Fast reads Cons: High write amplification (celebrity problem — 10M followers!)

Fan-Out on Read (Pull Model)

Feed is computed at read time from followed users' posts.

Pros: No write amplification Cons: Slow reads

Hybrid Approach

  • Regular users: Fan-out on write
  • Celebrity users (10K+ followers): Fan-out on read

Feed Storage

Redis: feed:{user_id} → [post_id_1, post_id_2, ...] (last 1000)
MySQL: posts table (source of truth)

Ranking

ML model scores posts by:

  • Recency
  • Engagement (likes, comments)
  • Relationship strength
  • Content type preference

Conclusion

Hybrid fan-out with Redis caching and ML ranking powers news feeds at billion-user scale.

Share this article