Bird
Raised Fist0
HLDsystem_design~15 mins

News feed generation in HLD - Deep Dive

Choose your learning style9 modes available
Overview - News feed generation
What is it?
News feed generation is the process of collecting, organizing, and displaying a personalized list of updates or posts for a user. It shows content from friends, followed pages, or topics in a way that is relevant and timely. This system helps users stay informed and engaged with what matters most to them.
Why it matters
Without news feed generation, users would have to manually check each source for updates, which is slow and overwhelming. A well-designed feed saves time and keeps users connected by showing the most important and interesting content first. It also helps platforms keep users engaged and satisfied.
Where it fits
Before learning news feed generation, you should understand basic data storage, user profiles, and content creation. After this, you can explore advanced topics like recommendation algorithms, caching strategies, and real-time updates.
Mental Model
Core Idea
News feed generation is about efficiently gathering and ranking content from many sources to show each user a personalized, timely list of updates.
Think of it like...
It's like a personal newspaper editor who collects articles from many reporters, chooses the most relevant stories for you, and arranges them on your front page in order of importance.
┌─────────────────────────────┐
│       User Request          │
└─────────────┬───────────────┘
              │
      ┌───────▼────────┐
      │ Content Sources │ (friends, pages, topics)
      └───────┬────────┘
              │
      ┌───────▼────────┐
      │ Aggregation    │ (collect posts)
      └───────┬────────┘
              │
      ┌───────▼────────┐
      │ Ranking &      │ (personalization, freshness)
      │ Filtering      │
      └───────┬────────┘
              │
      ┌───────▼────────┐
      │ Feed Delivery  │ (pagination, caching)
      └───────────────┘
Build-Up - 7 Steps
1
FoundationUnderstanding Content Sources
🤔
Concept: Learn what kinds of content come into a news feed and where they originate.
News feeds gather posts from various sources like friends, followed pages, groups, or topics. Each source produces content independently. The system must know who the user follows and what content is available from those sources.
Result
You can identify all possible content that could appear in a user's feed.
Knowing the origin of content is essential to collect the right data for each user’s feed.
2
FoundationBasic Feed Aggregation
🤔
Concept: Combine content from multiple sources into a single list for a user.
Aggregation means gathering all posts from the user's followed sources. This can be done by querying databases or message queues that store new posts. The system collects these posts before any sorting or filtering.
Result
A raw list of all possible posts for the user is ready for further processing.
Aggregation is the first step to unify scattered content into one place for easier handling.
3
IntermediateRanking and Personalization
🤔Before reading on: do you think news feeds show posts simply by time order or by importance? Commit to your answer.
Concept: Order the aggregated posts to show the most relevant and interesting ones first.
Ranking uses signals like post freshness, user interactions, content type, and user preferences to score each post. Personalization tailors the feed to each user's tastes and habits. Machine learning models or rule-based systems can be used.
Result
The feed shows posts in an order that maximizes user engagement and satisfaction.
Understanding ranking explains why feeds feel personal and why some posts appear before others.
4
IntermediateFeed Storage and Caching
🤔Before reading on: do you think the feed is generated fresh on every request or stored ahead of time? Commit to your answer.
Concept: Store precomputed feeds or parts of feeds to serve users quickly and reduce load.
Feeds can be generated on-demand or precomputed and cached. Precomputing means building the feed before the user requests it, often using background jobs. Caching stores these results in fast storage like memory or SSDs to speed up delivery.
Result
Users get their feeds with low delay, even under heavy load.
Knowing caching strategies helps understand how large platforms keep feeds fast and scalable.
5
IntermediateHandling Real-Time Updates
🤔
Concept: Incorporate new posts or interactions into the feed quickly after they happen.
Real-time updates use streaming systems or push notifications to add fresh content to feeds. This can involve event queues, pub/sub systems, or WebSocket connections to notify users of new posts without refreshing.
Result
Users see new content almost instantly, improving engagement.
Real-time handling is key to making feeds feel alive and responsive.
6
AdvancedScaling Feed Generation for Millions
🤔Before reading on: do you think one server can handle feed generation for millions of users? Commit to your answer.
Concept: Design the system to handle huge numbers of users and posts efficiently.
Scaling involves sharding data by user or content, using distributed caches, and parallel processing. Systems use asynchronous jobs, load balancers, and database replicas. Tradeoffs between freshness and performance are carefully balanced.
Result
The system can serve personalized feeds to millions without delays or crashes.
Understanding scaling reveals the complexity behind smooth user experiences on large platforms.
7
ExpertBalancing Freshness and Consistency
🤔Before reading on: do you think a feed always shows the absolute latest posts or sometimes delays updates? Commit to your answer.
Concept: Manage tradeoffs between showing the newest content and keeping the feed stable and consistent.
Feeds may delay some updates to avoid overwhelming users or to batch processing. Eventual consistency means some posts appear slightly later but the system remains scalable. Techniques like versioning, timestamps, and conflict resolution are used.
Result
Users get a feed that feels fresh but is also reliable and performant.
Knowing these tradeoffs helps understand why feeds sometimes show small delays and how systems maintain quality at scale.
Under the Hood
News feed generation works by first identifying all content sources relevant to a user. The system aggregates posts from these sources, then applies ranking algorithms to score and order them based on relevance and freshness. To serve feeds quickly, results are often precomputed and cached. Real-time updates use event-driven architectures to push new content. The system is distributed, using sharding and replication to handle scale. Consistency models balance freshness with performance.
Why designed this way?
This design evolved to handle billions of users and posts efficiently. Early systems generated feeds on-demand but became too slow as scale grew. Precomputing and caching improved speed but introduced freshness delays. Distributed architectures and event-driven updates allow balancing user experience with system resources. Alternatives like pure on-demand or fully push-based feeds were rejected due to performance or complexity issues.
┌───────────────┐       ┌───────────────┐       ┌───────────────┐
│ Content       │──────▶│ Aggregation   │──────▶│ Ranking &     │
│ Sources       │       │ Layer         │       │ Personalization│
└───────────────┘       └───────────────┘       └──────┬────────┘
                                                        │
                                                        ▼
                                               ┌───────────────┐
                                               │ Feed Storage  │
                                               │ & Caching    │
                                               └──────┬────────┘
                                                      │
                                                      ▼
                                               ┌───────────────┐
                                               │ Feed Delivery │
                                               │ (API/Push)    │
                                               └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does news feed generation always show posts strictly in reverse chronological order? Commit to yes or no.
Common Belief:News feeds just show posts in the order they were posted, newest first.
Tap to reveal reality
Reality:Feeds use complex ranking algorithms that consider many factors beyond time, like user preferences and engagement likelihood.
Why it matters:Assuming simple time order leads to poor design choices and misunderstanding why some posts appear unexpectedly.
Quick: Do you think feeds are always generated fresh on every user request? Commit to yes or no.
Common Belief:Feeds are created from scratch every time a user opens the app to ensure freshness.
Tap to reveal reality
Reality:Most large systems precompute and cache feeds to serve them quickly, updating them asynchronously.
Why it matters:Believing feeds are always fresh on demand ignores performance challenges and leads to unrealistic expectations.
Quick: Is it true that real-time updates mean users see new posts instantly without delay? Commit to yes or no.
Common Belief:Real-time feed updates guarantee immediate visibility of new posts to all users.
Tap to reveal reality
Reality:There is often a small delay due to batching, network latency, and consistency models.
Why it matters:Expecting instant updates can cause frustration and misinterpretation of system behavior.
Quick: Do you think one server can handle feed generation for millions of users alone? Commit to yes or no.
Common Belief:A single powerful server can generate all users' feeds efficiently.
Tap to reveal reality
Reality:Feed generation requires distributed systems with sharding and parallelism to scale.
Why it matters:Underestimating scale leads to designs that fail under real-world loads.
Expert Zone
1
Ranking algorithms often incorporate negative feedback signals, like hiding posts the user scrolls past quickly, which many overlook.
2
Precomputing feeds can be hybrid: some parts are precomputed while others are generated on-demand to balance freshness and cost.
3
Consistency models vary per platform; some tolerate eventual consistency in feeds to improve performance, which can surprise newcomers.
When NOT to use
News feed generation is not suitable for systems requiring strict real-time guarantees or absolute consistency, such as financial trading platforms. In those cases, event streaming or transactional systems are better.
Production Patterns
Large platforms use a combination of fan-out on write (precompute feeds when posts are created) and fan-out on read (generate parts of the feed when requested). They also use machine learning models for ranking and layered caching to optimize latency.
Connections
Recommendation Systems
News feed ranking builds on recommendation algorithms to personalize content.
Understanding recommendation systems helps grasp how feeds predict what users want to see.
Distributed Caching
Caching is critical to feed delivery performance in distributed systems.
Knowing caching strategies clarifies how feeds stay fast despite huge data volumes.
Supply Chain Management
Both involve aggregating inputs from many sources and prioritizing outputs efficiently.
Seeing feed generation like supply chains reveals universal principles of handling large, complex flows.
Common Pitfalls
#1Generating the entire feed on every user request causing high latency.
Wrong approach:On user request: query all followed sources, fetch all posts, rank, and return immediately.
Correct approach:Precompute feeds asynchronously, cache results, and serve cached feed on request.
Root cause:Misunderstanding the cost of on-demand aggregation and ranking at scale.
#2Ignoring personalization and showing the same feed to all users.
Wrong approach:Return posts sorted only by time without considering user preferences.
Correct approach:Apply ranking algorithms that use user behavior and preferences to order posts.
Root cause:Underestimating the importance of relevance for user engagement.
#3Assuming real-time means zero delay and pushing every new post instantly.
Wrong approach:Push every new post immediately to all followers without batching or filtering.
Correct approach:Use event queues and batch updates to balance freshness and system load.
Root cause:Not accounting for network and processing constraints in real-time systems.
Key Takeaways
News feed generation collects and ranks content from many sources to create a personalized list for each user.
Ranking and personalization are crucial to show relevant and engaging posts, not just the newest ones.
Precomputing and caching feeds improve performance and scalability for millions of users.
Real-time updates enhance user experience but require careful tradeoffs between freshness and system load.
Scaling feed generation involves distributed architectures, sharding, and balancing consistency with responsiveness.