AI Hints
Home›System Design Tutorial›Case Study: Chat and Feeds
System Design · Lesson 99 of 120

News Feed: Requirements

Posts from friends.

⏱ 2 min read▶ Video at 2:00:07🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Our next case study is a news feed, like on Facebook, Instagram, or X. You follow people, they post, and you see their posts on your home page.

News Feed: Requirements
From the video: News Feed: Requirements
  • You follow people
  • They post
  • You see a feed

Requirements

Functionally, users publish posts, follow other users, and see a feed of posts from the people they follow, newest or best first. Non functionally, the feed must load fast, under two hundred milliseconds. It can be slightly out of date. A post may take a few seconds to appear. And it must scale to hundreds of millions of users.

Functional

  • Publish postsFollow usersSee a feed

Non-functional

  • Feed under 200 msA little stale is fineHuge scale

The core problem

The heart of the problem is this. A user follows five hundred people. Building their feed means collecting recent posts from all five hundred, sorting them, and returning the top twenty. Doing that from scratch, on every page load, for millions of users, is far too slow. We need a smarter approach.

keyvalue
Follows~500 people
On each loadcollect, sort, top 20
From scratchtoo slow
Needa smarter approach

Summary

A news feed shows posts from the people you follow, quickly, at huge scale. Building it from scratch on every load is too slow. Next, the key idea. Fan out.

Key takeaways
  • Posts from people you follow
  • Fast, slightly stale is OK
  • Don't build from scratch
Next up: News Feed: Fan-Out — push or pull