Design a Social News Feed (like X/Twitter)
Design a feed for 500M users: posting tweets, and building each user's home timeline as new posts arrive.
Think of a news feed like a morning newspaper customized for you. Instead of printing every article in the world, the printer only binds pages written by the authors you subscribe to.
- Clients
- Phone or browser
- Entry
- API gateway
- Services
- Feed service
- Fan-out workers
- Queues, caches
- Post queue
- Feed cache
- Celebrity cache
- Data, outside
- Post store
1. Requirements and scope
- Users can post new tweets (text, images, video).
- Users can follow/unfollow other users.
- Users can see their home timeline: the tweets of everyone they follow, newest first.
- Support search by keyword and trending topics.
- High availability (99.99%). Low feed generation latency (< 200ms).
- Eventual consistency is acceptable (a new tweet can take 2-5 seconds to appear in followers feeds).
- Fan-out handling for celebrity accounts with 100M+ followers.
2. Back-of-the-envelope numbers
- Writes: 6,000 posts a second, on average (2%)
- Reads: 300,000 feed reads a second, on average (98%)
Read-heavy: about 50 reads for each write. A cache and extra read copies help most here.
3. API
4. Data model and storage
TWEETS: (tweet_id, user_id, content, created_at); TIMELINE: Redis List key="timeline:{userId}" with up to 800 tweet IDs.5. The design, in three versions
Version 1: Fan-out on Read (Pull Model)
When user views feed, join followers table with tweets table on the fly.
Social News Feed (like X/Twitter): Version 1: Fan-out on Read (Pull Model) Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Entry
3. Services
4. Data, outside
The steps in words0 of 4 steps shown
Phone or browser to API gateway
User 42 opens the home feed.
API gateway to Feed service
The gateway checks the login and passes the request on.
Feed service to Post store
It joins "who I follow" with all posts and sorts them. This is slow.
Feed service to Phone or browser
The feed goes back to the phone.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathPost a tweet
- Client
- Tweet service
- Kafka
- Fanout workers
- Redis timelines
- Celebrity cache
Client to Tweet service
Asha posts. The service saves the tweet in the tweet store and answers at once.
Tweet service to Kafka
It publishes a "new tweet" event.
Kafka to Fanout workers
Workers read the event and look up Asha's followers.
Fanout workers to Redis timelines
Asha has 200 followers, so the workers add the tweet id to 200 timeline lists.
Fanout workers to Celebrity cache
For an account over 25,000 followers, the workers skip that step. The tweet goes only into the account's own cache of recent tweets.
Read pathOpen the home timeline
- Client
- Timeline service
- Redis timelines
- Celebrity cache
- Tweet store
Client to Timeline service
Ben opens the app and asks for his home timeline.
Timeline service to Redis timelines
The service reads Ben's stored list of tweet ids.
Timeline service to Celebrity cache
It fetches recent tweets from the celebrities Ben follows.
Timeline service to Tweet store
It merges the two lists by time, keeps the top 20, and loads their text.
Timeline service to Client
It returns the page with a cursor: the id of the last tweet, used to ask for the next page.
What breaks, and what happens then
Fanout workers fall behind
- What users see
- New tweets appear in followers' feeds late.
- What the design does
- Kafka keeps the events, so nothing is lost. Add workers; the requirements allow a delay of a few seconds.
A Redis timeline node is lost
- What users see
- The stored timelines on it are gone.
- What the design does
- Rebuild a timeline on demand from the recent tweets of the accounts the user follows, then store it again.
A celebrity posts and millions open the app
- What users see
- The same few tweets are read millions of times.
- What the design does
- Those tweets are served from a cache, so the tweet store sees very few of the reads.
6. Deep dives
7. Follow-up questions
- How do you paginate tweets without duplicate items when new tweets are posted? (Answer: Use cursor-based pagination with tweet_id instead of OFFSET/LIMIT).
What it costs
Memory is the cost: ready-made timelines for 300 million daily users need about 1.9 TB of Redis. Keep timelines only for users who were active lately, and build the rest when they return.
Another way to design it
You can build every timeline at read time and store none. Posting is then cheap, and each read does more work. That fits a product where most users follow few accounts and read rarely.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 6,000 tweets a second and 300,000 timeline reads a second, 50 reads per write. It pushes new tweets into each follower's cached timeline and goes deep on one part.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Users post tweets and follow others; the home timeline shows tweets from people they follow, in time order. Since the spec allows a tweet to reach a follower a few seconds late, I will design for that instead of instant delivery. I will size the system for 50 reads per write.
Users write a tweet, and it should show up in every follower's timeline the instant they refresh, no matter how many followers they have. Let me start on the fan-out service.
Shows: Unclear questionsThe difference: The weak answer assumes instant delivery for every account, when the problem accepts a few seconds of delay. That assumption shapes the whole design.
Estimates
500 million tweets a day is about 6,000 a second on average, and 20,000 at peak. At 50 reads per write, average reads are about 300,000 a second, with a stated peak of 600,000. At 300 bytes a tweet, a year of tweets is about 55 TB.
6,000 tweets a second is the number I will build for, since that covers the normal load the service sees most of the time.
Shows: ScopeThe difference: Sizing for the average alone misses the stated 20,000 peak writes and 600,000 peak reads, when news events hit. The strong answer plans for both.
Core design
When a tweet is posted, a worker pushes its ID into a Redis list for each follower. A timeline read then becomes one fast list fetch. Tweets themselves live in Cassandra, keyed by tweet ID, since writes are frequent and a simple key lookup by ID spreads easily across many machines.
When a user opens their timeline, the server runs a query that joins the tweets table with the follows table. It orders the join by time and returns the newest tweets.
Shows: DepthThe difference: A live join for every one of 300,000 reads a second is too slow at that rate. Pushing tweet IDs into each follower's list ahead of time avoids it.
Deep dive
The hard part is celebrities: pushing one tweet to 100 million followers' lists would overload the cluster. So accounts over about 25,000 followers skip the push. A read merges their few recent tweets with the reader's normal pushed timeline, sorted together.
Since push writes are fast, I would push every tweet to every follower's list the same way, including for the biggest accounts.
Shows: DepthThe difference: Pushing one tweet to 100 million lists overloads the cluster; the weak answer never treats celebrities differently. The strong one pulls their tweets instead.
Failures and trade-offs
We accept a tweet reaching followers a few seconds late, but one bad tweet must not stall the rest. Workers track their progress in the stream, so a crash resumes where it stopped. A tweet that keeps crashing a worker moves to a dead-letter queue after a few tries, so the tweets behind it still flow.
If a fan-out worker crashes on a tweet, it restarts and tries that same tweet again. It keeps trying as many times as it takes before moving on.
Shows: ScopeThe difference: A tweet that always crashes the worker is retried forever, so every tweet queued behind it stalls. Moving it aside after a few tries keeps fan-out flowing.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
9. One problem, four levels
The same question, "design a news feed", answered at four levels. Each column shows only what that level adds to the one before it.
| Part of the answer | Junior | Mid adds | Senior adds | Staff adds |
|---|---|---|---|---|
| Requirements and scope |
|
|
|
|
| Estimates |
|
|
|
|
| Core design |
|
|
|
|
| Deep dive |
|
|
|
|
| Failures and trade-offs |
|
|
|
|
Requirements and scope
- A working design lets a user post a tweet, follow others, and see a timeline of tweets from people they follow.
- New at MidSplits must-haves (post, follow, timeline) from qualities: a new tweet can take a few seconds to reach followers, and reads far outnumber writes.
Estimates
- Says the system is read-heavy: far more people check timelines than post new tweets.
- New at MidAbout 6,000 tweets a second on average, and 300,000 timeline reads a second, about 50 reads for every write.
Core design
- An API to post a tweet, a follows table, and a timeline built by fetching tweets from people a user follows.
- New at MidWhen a tweet is posted, its ID is pushed into a cached list for each follower, so a timeline read is one fast list fetch.
Deep dive
- Explains why pulling tweets on read works at first: joining tweets and follows finds new posts without needing extra storage.
- New at MidExplains why pushing on write is faster to read: a timeline becomes one list fetch instead of a live join across two tables.
Failures and trade-offs
- Says the tweet store needs a backup, so posts are not lost if a server fails.
- New at MidSaves each tweet to the tweet store before fan-out starts, so a fan-out crash never loses the tweet itself.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Social News Feed (like X/Twitter) Design a feed for 500M users: posting tweets, and building each user's home timeline as new posts arrive. What users must be able to do: - Users can post new tweets (text, images, video). - Users can follow/unfollow other users. - Users can see their home timeline: the tweets of everyone they follow, newest first. - Support search by keyword and trending topics. How well it must work: - High availability (99.99%). Low feed generation latency (< 200ms). - Eventual consistency is acceptable (a new tweet can take 2-5 seconds to appear in followers feeds). - Fan-out handling for celebrity accounts with 100M+ followers. Numbers to assume: - 300 Million DAU, 500 Million tweets posted daily (~6,000 tweets/sec avg). - Read-to-write ratio: 50:1 (~300,000 timeline reads/sec). Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 6,000 tweets a second and 300,000 timeline reads a second, 50 reads per write. It pushes new tweets into each follower's cached timeline and goes deep on one part. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]