Design a News Feed
This breakdown designs the home feed of a social network: people follow each other, post, and open the app to a list of recent posts from everyone they follow. It is written for mid-level and senior software engineers and follows the delivery framework from System Design Interviews: The Quick Start. The interesting part is not storing posts. It is deciding when the work of assembling each feed happens, and what to do about the account with fifty million followers.
Requirements
Functional
A user can follow and unfollow other users.
A user can create a post (text, optionally with images).
A user can open their feed and see posts from the people they follow, newest first, scrolling back with pagination.
Ranking by relevance, likes and comments are usually out of scope; mention ranking and agree to treat it at a high level near the end.
Non-functional, with numbers
200 million daily active users opening the feed about 10 times a day: 2 billion feed reads a day, about 23,000 per second on average and roughly double at peak.
Half of daily users post once a day: 100 million posts a day, about 1,160 per second.
The average user has 200 followers, but the distribution is skewed: some accounts have tens of millions.
Reads outnumber writes by about 20 to 1, so the design should make reads cheap.
Feed loads should return in under about 200 milliseconds; a new post may take a few seconds to appear in followers' feeds. That second point is eventual consistency, and agreeing on it unlocks the whole design.
Core entities and API
Entities: User, Follow (follower, followee, created at), Post (id, author, text, media references, created at) and FeedEntry (owner, post id, created at).
POST /users/{userId}/follow -> 204
DELETE /users/{userId}/follow -> 204
POST /posts { text, mediaIds } -> { postId }
GET /feed?cursor=&limit=20 -> { posts: [...], nextCursor }Use a cursor for pagination, not page numbers. The cursor encodes the last item's (createdAt, postId), so new posts arriving at the top never shift what the next page returns. API Design covers cursors in more depth.
Media uploads go straight to object storage through pre-signed URLs and are served through a CDN; the post only stores references. Handling Large Files explains that flow.
High-level design: three ways to build a feed
Fan-out on read (pull)
When a user opens their feed, look up everyone they follow, fetch each one's recent posts, merge by time and return the top 20. Writes are trivial. Reads are expensive: a user following 500 accounts triggers 500 lookups on every open, at 23,000 opens per second. The latency budget does not survive that.
Fan-out on write (push)
When someone posts, a background worker looks up their followers and appends the post id to each follower's precomputed feed list. Reading a feed becomes one lookup of a list that is already sorted. The cost moves to writes: 100 million posts a day times 200 followers is 20 billion feed insertions a day, about 231,000 per second. That is a lot, but it is spread across many workers and shards, and it happens asynchronously, so the poster never waits.
Hybrid: push for most, pull for the few
Push breaks for the very large accounts. One post from an account with 50 million followers means 50 million insertions; even at a million insertions a second across the cluster, the last followers see it nearly a minute later, and a few such accounts posting at once can swamp the workers.
So split by follower count:
Accounts below a threshold, say 100,000 followers, fan out on write as usual.
Accounts above it do not fan out. Their posts are pulled at read time.
When a user opens the feed, read their precomputed list, then fetch recent posts from the few large accounts they follow, merge, and return.
Most users follow only a handful of large accounts, so the pull part is a few lookups, each one cacheable because millions of readers want the same recent posts from the same accounts.
Post ---> Post service ---> Posts store
|
v
Fan-out queue ---> Fan-out workers ---> Feed cache (per user)
^
Follow graph service
Feed read ---> Feed service ---> Feed cache (precomputed ids)
|-------> Recent posts of followed large accounts (cached)
|-------> Post hydration (post + author details, cached)This is the answer the interviewer is hoping you reach and justify with numbers. Queues and Event Streams covers the queue between posting and fan-out.
Deep dive 1: feed storage
Store each user's feed as a list of post ids ordered by time, capped at a length such as 500 entries. A sorted set in an in-memory store, keyed by user id and scored by timestamp, fits well: insertion and range reads are logarithmic, and trimming old entries is one call.
Size it: 500 entries at about 16 bytes (id plus timestamp) is 8 KB per user. For 200 million users that is 1.6 TB of raw data. An in-memory sorted set adds several times that in per-entry overhead, so either budget for a multiple of 1.6 TB or store each feed as a compact array of ids and accept rewriting it on insert. Either way it splits evenly across a cluster sharded by user id. Two refinements bring it down:
Keep precomputed feeds only for users active in the last few weeks. When an inactive user returns, rebuild their feed once with a pull and resume pushing.
Store only ids in the feed. Post bodies and author details are fetched in a batched "hydration" step from their own caches, so an edited post or a renamed author does not need millions of feed entries rewritten.
When the user scrolls past the 500 cached entries, fall back to pulling older posts from the posts store. Few people scroll that far, so this path can be slower.
Deep dive 2: the follow graph
Store follows as rows of (followerId, followeeId, createdAt), with two access paths: "who does this user follow" (for the pull and for rebuilding a feed) and "who follows this user" (for fan-out). In a sharded store, that usually means two copies of the edge, one partitioned by follower and one by followee, written together. Fan-out workers page through the follower list in batches of a few thousand rather than loading 100,000 ids at once.
Follow and unfollow are edge cases worth naming. A new follow can backfill the followee's last few posts into the follower's feed; an unfollow can filter that author's posts out at read time rather than deleting entries from the stored list.
Deep dive 3: ranking, at a high level
A chronological feed is a sort. A ranked feed adds two stages:
Candidate generation: the precomputed list plus the large-account pull gives a few hundred candidate posts.
Scoring: a model predicts how likely the user is to engage with each candidate from features such as the author relationship, the post's age and early engagement. Sort by score, then apply rules such as not showing three posts from one author in a row.
Ranking changes pagination: a scored order is not stable as new posts and likes arrive, so the first request computes a ranked page set for the session and the cursor walks that snapshot. ML System Design Interviews covers how to talk about the model itself.
Follow-ups to expect
"What happens when a celebrity posts?" They are above the threshold, so nothing fans out; followers pull their recent posts, which sit in a hot cache entry shared by millions of readers. Replicate that entry across cache nodes so one node does not take all the traffic.
"A user follows 5,000 accounts. Still fast?" The push path makes following many accounts cheap to read. Only the large-account pull grows, and it is bounded by how many large accounts they follow.
"How do you handle a post being deleted?" Mark it deleted in the posts store; hydration drops it at read time. Optionally a background job removes the id from feeds, but correctness does not depend on it.
"What if the feed cache cluster loses a node?" Feeds on it rebuild lazily with a pull on next open. It is a cache, so the durable truth (posts and follows) is elsewhere.
"How fresh is the feed?" Seconds for normal accounts, depending on queue lag, which is the metric to alert on.
What changes with seniority
Mid-level: explains push versus pull with their costs and lands on a working design with cursor pagination.
Senior: quantifies the fan-out load, introduces the hybrid with a threshold and justifies it, sizes the feed cache, and handles inactive users and hydration.
Staff: discusses the threshold as a tunable with metrics, multi-region feeds, ranking as its own system with experiment infrastructure, and the cost of the memory footprint against latency targets.
Mistakes that cost points
Choosing pull or push without numbers. The decision depends on the read and write rates and the follower distribution; show them.
Storing whole posts in every feed. It multiplies storage and makes edits and deletes expensive. Store ids, hydrate on read.
Offset pagination. New posts shift every page. Use a cursor.
Forgetting the large accounts until asked. Raise the skew when you state requirements, then design for it.
Practice it
Take 15 minutes to redo the fan-out arithmetic with different assumptions (1,000 average followers, 10 million posts a day) and decide where the hybrid threshold should move. Then practice in a live interview:
Design a Real-Time Chat System, where group messages raise the same fan-out question
Design a URL Shortener, the same read-heavy caching trade-offs at a smaller scale
Practise this in a mock interview
Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.
- Design a URL ShortenerSystem Design · Medium
- Design a Rate Limiter ServiceSystem Design · Medium
- Design Live Score Alert FanoutSystem Design · Medium
- Design a Video Upload and Transcoding PipelineSystem Design · Medium
Read next
- Design a Ticket Booking System
Design event ticketing end to end: hold seats without double-selling, absorb a million-fan on-sale with a virtual waiting room, serve availability from cache, and handle a payment that succeeds after its hold expired.
9 min read
- System Design Interviews: The Quick Start
Know which system design interview you face and how depth expectations change by level, then deliver any design with a six-step, 45-minute framework whose estimates drive real decisions.
7 min read
- ML System Design Interviews: The Quick Start
Run an ML system design interview with an eight-step, 45-minute framework, from framing and labels to metrics, serving, drift and feedback loops, worked through on a harmful-comment classifier.
9 min read
- Thinking in Systems: From One Server to Millions of Users
Explain why each part of a typical web architecture exists by growing one app from a single server to millions of users, naming what broke and what each fix costs.
7 min read
