πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Design a News Feed System

System Design ProblemsSocial Media Feed🟒 Free Lesson

System Design Problems

Design a News Feed System

A news feed system displays a personalized stream of posts from users a person follows. The core challenge is fan-out: a single post by a popular user must be delivered to millions of followers in near real-time.

  • Fan-out on Write β€” Pre-compute feeds when a post is published (push model)
  • Fan-out on Read β€” Compute feeds dynamically when a user loads their feed (pull model)
  • Hybrid Approach β€” Combine both strategies based on follower count

The fundamental tension: pre-computing feeds is fast to read but expensive to write; computing on-the-fly is cheap to write but slow to read.

Requirements

Functional Requirements

  • Users can create posts (text, images, videos)
  • Users see a personalized feed of posts from people they follow
  • Feed is sorted by time (or relevance/ranking)
  • Users can like, comment, and share posts
  • New posts appear in followers' feeds within seconds
  • Support for trending topics and discovery

Non-Functional Requirements

  • Latency: Feed loads in < 200ms
  • Throughput: 500K feed reads/sec, 50K posts/sec
  • Freshness: New posts visible within 5 seconds
  • Consistency: Eventual consistency is acceptable
  • Scalability: 500M users, 100M daily active users

Back-of-the-Envelope Estimation

Feed Generation Strategies

Push Model (Fan-out on Write)Post CreatedFan-out toFollowersWrite to Feed Cacheβœ“ Fast reads | βœ— Slow writesPull Model (Fan-out on Read)Feed RequestQuery AllFolloweesMerge & Rankβœ“ Fast writes | βœ— Slow readsHybrid ModelCelebrity?Yesβ†’PullNoβ†’PushBest of Both Worldsβœ“ Balanced | βœ“ Scalable

Hybrid Strategy

The hybrid approach handles the celebrity problem:

Detailed Design

Data Models

Architecture Diagram
// Post
{
  post_id: "p_123",
  user_id: "u_456",
  content: "Hello world!",
  media_urls: ["https://..."],
  created_at: "2026-06-20T10:00:00Z",
  like_count: 42,
  comment_count: 5
}

// Feed (per user, stored in Redis sorted set)
// Key: feed:{user_id}
// Score: post timestamp
// Value: post_id

Feed Storage

Use Redis sorted sets for feed storage:

Architecture Diagram
ZADD feed:u_789 1687267200 p_123
ZADD feed:u_789 1687267100 p_122
ZREVRANGE feed:u_789 0 19  // Get 20 most recent posts

Ranking Algorithm

Feed items can be ranked by time or by relevance:

Real-time Updates

For real-time feed updates, use WebSockets or Server-Sent Events (SSE):

  1. User connects via WebSocket
  2. When a followed user posts, push the new post via WebSocket
  3. Client inserts the post at the top of the feed
  4. For batch updates, poll every 30 seconds

Scaling Considerations

Database Sharding

Partition the posts table by user_id hash:

Architecture Diagram
shard = hash(user_id) % NUM_SHARDS

This co-locates all posts by the same user on the same shard, enabling efficient queries for "get all posts by user X."

Feed Cache Sizing

Practice Exercises

  1. Design: How would you implement a "For You" personalized feed that uses machine learning to rank posts based on user preferences? What features would you use?

  2. Scale: If a celebrity with 50M followers publishes a post, estimate the time and resources needed to fan out the post to all followers using the push model.

  3. Consistency: How would you handle the case where a user unfollows someone but still sees their posts in the feed? Design a feed invalidation strategy.

  4. Trade-offs: Compare push, pull, and hybrid feed generation for a system with 100M users where 0.1% are celebrities (10M+ followers).


What to Learn Next

-> Design Chat System Real-time messaging with WebSocket and presence tracking.

-> Event-Driven Architecture Event sourcing, CQRS, and asynchronous communication.

-> Caching Strategies Cache-aside, write-through, and distributed caching patterns.

-> Message Queues Kafka, RabbitMQ, and event-driven fan-out.

-> Design Recommendation System ML-based content ranking and personalization.

-> Data Replication Replication strategies for high-availability data access.


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type β€” Always start by categorizing the problem
  2. Incorrect formula application β€” Verify the formula applies to your specific case
  3. Unit errors β€” Always check units are consistent throughout
  4. Sign errors β€” Pay careful attention to positive and negative values
  5. Rounding too early β€” Keep full precision until the final answer
  6. Forgetting constraints β€” Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement