Design a news feed (Twitter)
Design the home timeline for a social product. People follow each other; when you open the app you see recent posts from everyone you follow, newest first. Some accounts have tens of millions of followers.
About this problem
“Design a news feed (Twitter)” is a core-level problem in the write-heavy / fan-out family. One action by one person creates work for thousands of other people.
The key challenge: A reader cannot tell when a post was supposed to appear in their feed. So you have seconds of slack on delivery, and almost none on opening the app.
Time budgets: Reads: ~200 ms. Post visibility: seconds. Counts: minutes.
The worked solution for Follower timeline goes through why those budgets shape the design, stage by stage.
Before you start
You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.
- Stage 1 · Requirements · 5 min
- The follower distribution is the assumption that matters most here. Say it.
- Is the timeline strictly chronological, or ranked? That question changes boxes.
- What is the read:write ratio for opening the app versus posting?
- Stage 2 · Actors and lifecycle · 6 min
- The system makes several decisions here that nobody asked it to. What are they?
- A post has a life, and so does a follow. Which one is more interesting?
- What happens to a post when the fan-out job dies halfway through?
- Stage 3 · Numbers · 6 min
- Posts per second is easy. Now multiply by the average follower count.
- What does the same number look like for the biggest account?
- Timeline opens per second: that is the read number.
- Stage 4 · High-level design · 12 min
- Push or pull, and why not just one of them?
- What is the inbox, physically? What is it keyed by?
- Where does the threshold between the two paths come from?
- Stage 5 · Deep dive and tradeoffs · 14 min
- The numbers pointed at amplification in the tail. What else did they show?
- What happens when the fan-out queue backs up an hour?
- How does pagination work when the feed comes from two sources?
Work it through
Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.
Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.
How it is really built
Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.
- Engineering at Meta ↗Fan-out and the celebrity problem, from the people who hit it first at this size.