Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design a Social News Feed (like X/Twitter)

Asked from Mid level upDomain: Social & Feed Systems
Concepts to know first:

Design a feed for 500M users: posting tweets, and building each user's home timeline as new posts arrive.

An analogy

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.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Phone or browser
  2. Entry
    • API gateway
  3. Services
    • Feed service
    • Fan-out workers
  4. Queues, caches
    • Post queue
    • Feed cache
    • Celebrity cache
  5. Data, outside
    • Post store

1. Requirements and scope

Functional Requirements
  • 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.
Non-Functional Requirements & SLAs
  • 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.
Key Traffic Assumptions: 300 Million DAU, 500 Million tweets posted daily (~6,000 tweets/sec avg). • Read-to-write ratio: 50:1 (~300,000 timeline reads/sec).

2. Back-of-the-envelope numbers

Writes and reads each second
  • 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.

Write Throughput
6,000 QPS (Avg), 20,000 QPS (Peak)
Read Throughput
300,000 QPS (Avg), 600,000 QPS (Peak)
Storage Growth
500M tweets × 300 Bytes × 365 = ~55 TB / year (Text only)
RAM Cache Footprint
Home timelines for all 300M DAU: 300M × 800 tweet IDs × 8 bytes ≈ 1.9 TB of Redis RAM across a cluster (IDs only, before Redis overhead)

3. API

POST/api/v1/tweetsPost tweet: { userId, content, mediaIds? }
GET/api/v1/timeline/homeGet paginated home timeline: ?page=1&limit=20
POST/api/v1/users/{id}/followFollow user

4. Data model and storage

Storage Strategy: Cassandra / ScyllaDB for Tweet storage + Redis Cluster for pre-computed Home Timeline lists.
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.

Phone or browserAPI gatewayFeed servicePost store1234
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Phone or browseropens the home feed

2. Entry

API gatewaychecks the login

3. Services

Feed servicebuilds the feed

4. Data, outside

Post storeevery post

The steps in words0 of 4 steps shown

  1. Phone or browser to API gatewayHTTPS · 2 ms

    User 42 opens the home feed.

  2. API gateway to Feed servicecall · 3 ms

    The gateway checks the login and passes the request on.

  3. Feed service to Post storequery · 8 ms

    It joins "who I follow" with all posts and sorts them. This is slow.

  4. Feed service to Phone or browserreply · 20 ms

    The feed goes back to the phone.

Why this version
Each tweet is stored once, so posting is one quick write.
Next bottleneck
At 300,000 timeline reads a second, each one a join across every account the reader follows, one database cannot keep up.

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

  1. Client
  2. Tweet service
  3. Kafka
  4. Fanout workers
  5. Redis timelines
  6. Celebrity cache
  1. Client to Tweet service

    Asha posts. The service saves the tweet in the tweet store and answers at once.

  2. Tweet service to Kafka

    It publishes a "new tweet" event.

  3. Kafka to Fanout workers

    Workers read the event and look up Asha's followers.

  4. Fanout workers to Redis timelines

    Asha has 200 followers, so the workers add the tweet id to 200 timeline lists.

  5. 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

  1. Client
  2. Timeline service
  3. Redis timelines
  4. Celebrity cache
  5. Tweet store
  1. Client to Timeline service

    Ben opens the app and asks for his home timeline.

  2. Timeline service to Redis timelines

    The service reads Ben's stored list of tweet ids.

  3. Timeline service to Celebrity cache

    It fetches recent tweets from the celebrities Ben follows.

  4. Timeline service to Tweet store

    It merges the two lists by time, keeps the top 20, and loads their text.

  5. 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

Hybrid Fan-Out Strategy
Users with <25,000 followers use Fan-out on Write (workers append tweetId to followers Redis lists). Users with >25,000 followers are flagged as Celebrities; their tweets are NOT fanned out. When a follower opens their feed, the timeline service pulls the celebrity tweets and merges them with the Redis timeline list in memory. It then returns the unified, sorted feed.

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.

How each level is judged
What is judgedJuniorMidSeniorStaff
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

Strong answer
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.
Weak answer
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

Strong answer
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.
Weak answer
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

Strong answer
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.
Weak answer
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

Strong answer
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.
Weak answer
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

Strong answer
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.
Weak answer
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.

What each level adds, part by part
Part of the answerJuniorMid addsSenior addsStaff adds
Requirements and scope
  • A working design lets a user post a tweet, follow others, and see a timeline of tweets from people they follow.
  • Splits must-haves (post, follow, timeline) from qualities: a new tweet can take a few seconds to reach followers, and reads far outnumber writes.
  • Asks about celebrity accounts, search and trending topics before designing, and says which of these this answer leaves out.
  • Questions whether every follower needs the same freshness. A ranked feed for the most active users may be worth more than showing every tweet.
Estimates
  • Says the system is read-heavy: far more people check timelines than post new tweets.
  • About 6,000 tweets a second on average, and 300,000 timeline reads a second, about 50 reads for every write.
  • Uses the numbers to decide: at peak, 20,000 writes and 600,000 reads a second, so both fan-out and read paths must scale.
  • Adds cost: keeping a precomputed timeline for every user, active or not, costs memory that mostly sits unused.
Core design
  • An API to post a tweet, a follows table, and a timeline built by fetching tweets from people a user follows.
  • When a tweet is posted, its ID is pushed into a cached list for each follower, so a timeline read is one fast list fetch.
  • Tweets themselves live in a store built for fast writes, keyed by tweet ID, separate from each follower's pushed list of tweet IDs.
  • Keeps a bot check on posting, since a few accounts can flood the write path far past 20,000 tweets a second.
Deep dive
  • Explains why pulling tweets on read works at first: joining tweets and follows finds new posts without needing extra storage.
  • Explains why pushing on write is faster to read: a timeline becomes one list fetch instead of a live join across two tables.
  • Goes deep on the celebrity problem: pushing one tweet to 100 million followers overloads the cluster, so accounts past about 25,000 followers skip the push.
  • Goes deep on the hybrid read: a celebrity's few recent tweets are merged with the reader's pushed list and sorted together at read time.
Failures and trade-offs
  • Says the tweet store needs a backup, so posts are not lost if a server fails.
  • Saves each tweet to the tweet store before fan-out starts, so a fan-out crash never loses the tweet itself.
  • A crashed fan-out job resumes from its last saved position, so it never skips a follower, only delays their timeline briefly.
  • Accepts a short delay everywhere, since guaranteeing instant delivery for every account would cost far more than the delay is worth.
Whole answer at:

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.]