Design a news feed like Facebook's
hard 50 minShow each person the best recent posts from everyone they follow, in a fifth of a second.
Video lesson · Chapter 1 of 5
A feed opens for just one reader
Theory
Read or listen first. About 2 min.
What it is
A news feed is a list of recent posts from the people, pages and groups you follow, put in an order that suits you. Opening the app asks one question: of everything these accounts wrote, which twenty posts should I see now?
Two actions meet here. Writing a post is rare and small. Reading a feed is frequent and touches hundreds of accounts. The design is about moving work from the frequent action to the rare one, without letting one famous writer break it.
Why it exists
Nobody wants to visit 500 profiles to find out what is new. A feed gathers it in one place, so it becomes the first screen people see and the busiest read path in the product.
It is asked often in interviews because a simple model (posts, follows, sort by time) turns into real trade-offs very fast: copy data early or gather it late, be fresh or be fast, be clever or be available.
A short history
2006
Facebook redesigns its pages and introduces News Feed in September. Some users protest at seeing every friend's activity in one list.
2010
The paper "Feeding Frenzy" (SIGMOD) shows how to choose push or pull separately for each pair of producer and consumer.
2011
Facebook changes the feed from strictly newest-first to a mix of top stories and most recent stories.
2012 to 2013
Raffi Krikorian's QCon talk "Timelines at Scale" describes how Twitter delivers posts into ready-made timelines. InfoQ publishes the recording in April 2013.
2013
Facebook publishes TAO, its store for the social graph, at USENIX ATC. The paper reports a billion reads a second.
2021
Meta's engineering blog describes ranking in passes: a light model keeps about 500 posts, a heavier one scores them, a last pass adds diversity.
Words to know
- Fan-out
- Turning one post into many deliveries.
- Push (fan-out on write)
- Copy the post's ID into each follower's ready feed when it is written.
- Pull (fan-out on read)
- Gather posts from followed accounts when the feed is opened.
- Ready feed
- A stored list of post IDs for one person, built before they ask.
- Hydration
- Replacing IDs with full posts: text, names, pictures, counts.
- Candidate
- A post that may be shown, before ranking decides.
- Big account
- An account above a follower limit, whose posts are pulled, not pushed.
- Read your own writes
- You see your own post at once, even when others do not yet.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
Understand it
Picture it
The paper round and the notice wall
Who walks: the paper carrier or the reader? A good design uses each where it is cheap.
Scope
What are we building?
A service like Facebook's news feed: people post, friends and followers see it in a personal, ranked, endless list. Similar products share the shape, each with one twist. The company's real system is not described here, except where we link its own engineering pages.
Similar applications
| Product | The twist |
|---|---|
| X (Twitter) | Timeline of short posts; one-way follows, so follower counts are very uneven |
| Pictures first, so media delivery dominates | |
| Professional posts; connections of connections matter | |
| TikTok | Mostly recommendations, little follow graph |
| Communities, not people: one feed per community is shared by many | |
| YouTube | Home feed of long videos |
| Saved pictures grouped by interest | |
| Threads | Short text posts with a follow graph |
Why it is interesting
Fan-out
One post may become 500 deliveries, or 100 million.
Read-heavy
About 50 feed requests for every post.
Personal
No two people get the same list, so the CDN cannot cache it.
Private
Copies travel ahead of permission changes. Reads must check.
The finished system
Where the design ends up
This is the last version, not the first. Design starts with one service and one database and names the break that forces each box.
The whole system
Where to read what
| Question | Interview tab | Concept page that owns the idea |
|---|---|---|
| What must it do? | Scope | Scoping |
| How big is it? | Numbers | Back of the envelope |
| What is the interface? | API and data | Pagination, file uploads |
| How does it grow? | Design | Push and pull, pub-sub |
| What is hard? | Deep dives | Thundering herd, real-time APIs |
| Why this choice? | Explain | Choosing and defending |
| Can I do it aloud? | Mock | 45 minutes |
Summary
The whole topic in one minute.
A feed reads far more than it writes: here 231,000 feed requests a second against 4,600 posts. So we do the work when a post is written. Workers copy its ID into the ready feed of every follower, and a read becomes one lookup.
Copying breaks for accounts with millions of followers, so their posts are kept once and merged in at read time. Ranking chooses the order, a post cache turns IDs into posts, and every read checks again that the viewer may see each post, because a copied ID is never permission.
- Push costs posts times followers; pull costs reads times follows. Compare the two numbers before choosing.
- Store IDs in ready feeds, full posts once.
- Big accounts are few, so their recent posts fit in every feed server's memory.
- Rank once for each visit and page through that result, or posts will repeat.
- If ranking fails, show newest first. Never show nothing.
- Check deletion, blocks and audience at read time, every time.
Sources
- Meta Engineering: how ranking for News Feed works (2021)
- TAO: Facebook's distributed data store for the social graph (USENIX ATC 2013)
- Feeding Frenzy: selectively materializing users' event feeds (SIGMOD 2010)
- Timelines at Scale, QCon (InfoQ)
- Redis: memory optimization
- HTML Standard: server-sent events
- Wikipedia: Feed (Facebook)