System Design Interview: Design a News Feed (Fan-out on Write vs Read) | OfferBull

System Design Interview: Design a News Feed (Fan-out on Write vs Read)
“Design a news feed.”
Sometimes they add “like Instagram” or “like Twitter.” Either way, a lot of candidates jump to a ranking model. Twenty minutes later there is a machine-learning box on the board and still no answer to a simpler question: when someone posts, whose feed gets updated, and when?
This is a full worked walkthrough of a design a news feed system design prompt: requirements and numbers, the fan-out on write versus fan-out on read trade (and a hybrid), ranking only at a high level, caching and sharding, then the follow-ups that usually arrive around minute 35. For the clock and the section order, use the system design interview template. The numbers, dialogues, and design choices below are illustrative interview-prep frameworks, not a claim about how any named social app builds its production feed.
Requirements and the numbers I’d put on the board
I’d get the follow graph on the table before I pick a model. This is a home feed of accounts you follow, not a full social network. Comments, ads, direct messages, and stories can wait unless they ask.
A clarifying exchange might sound like this (illustrative):
You: “I’d design the home feed: people post, followers see those posts in a personalized list. I’d leave a public global timeline, ads, and a comment system out unless you want them in scope. Ranking can stay simple unless you want a model-heavy deep dive. What scale should I assume?”
Interviewer: “Say 20 million daily users. Some accounts have millions of followers.”
You: “I’ll assume a typical user follows about 200 accounts and opens the feed around 10 times a day. Most people post once a day or less. A small set of celebrity accounts have two to ten million followers. The feed should feel instant. A new post can take a few seconds to show up for every follower. Fair?”
Then I talk through a few numbers, rounded, so they can argue with me. 20 million daily users, each posting once, is 20 million posts a day, about 230 writes a second. A 3x peak, just as an interview assumption, is still under a thousand posts a second. Feed reads are heavier: 20 million users times 10 opens is 200 million reads a day, about 2,300 a second, or around 7,000 at a 3x peak. Follow graphs are uneven. If an ordinary user has a few hundred followers, a celebrity post to five million people is a different write problem than the average case.
Those numbers already lean one way. The post write rate is comfortable. The feed read rate is not huge either, but users are waiting on that path, so I want reads to be cheap for ordinary accounts. The thing that will break a careless design is not “20 million posts a day.” It’s one user with five million followers hitting “post.”
Non-functional requirements, said as one-liners: opening the home feed should be fast, a new post can take a few seconds to appear everywhere, the service should survive the loss of a cache node or a timeline shard, and we will filter deleted posts and blocks at read time even if a stale pointer is still sitting in someone’s inbox.
Get the follow count and the celebrity case on the board before you pick a fan-out model.
Fan-out on write vs fan-out on read, and ranking at a high level
This is the deep dive I’d offer first. What they want is two or three options, a pick, and the cost of that pick. Interviewers have heard “I’ll just push the post to all followers” plenty of times.
Fan-out on write, sometimes called a push model: when you post, a worker inserts that post ID into each follower’s timeline, a denormalized inbox of recent post IDs. Reading the feed is then a cheap range read of your inbox, plus a lookup to hydrate the posts. For a user with 400 followers, one post becomes 400 small writes, which a queue can absorb. For a user with five million followers, one post becomes five million writes. The send path can’t wait on that, and even a background job will heat a lot of timeline shards at once. My honest take? This is a strong default for ordinary accounts, and a bad default for celebrities.
Fan-out on read, a pull model: a post is written once, to that author’s post store. When you open the feed, the service fetches recent posts from the accounts you follow, merges them, ranks them, and returns a page. Writes stay cheap, including celebrity writes. The cost moves to the read path. Following 200 accounts means up to 200 lookups, or a slightly smaller number if you keep a per-author recent-post cache. Following 2,000 accounts makes this painful, and every refresh repeats the work unless you cache the merged page.
A hybrid is the option I’d pick in most versions of this interview. Ordinary accounts still fan-out on write, so most feeds are precomputed. Accounts above some follower threshold, say 100,000 as an interview number, are marked as celebrity and are not pushed into millions of inboxes. At read time, you merge the precomputed inbox with recent posts from the celebrity accounts the user follows. Cheap reads for the common case, and you don’t melt the cluster when a famous account posts a photo.
I’d say the costs out loud. You need a way to mark celebrity accounts, and a user who crosses the threshold should stop being pushed. The read path is no longer “just read my inbox.” It has a merge step. If someone follows 50 celebrities, that merge is still bounded, which is why the threshold exists.
The same shape shows up in a chat app design when a group has 10,000 members: write once, or copy to every inbox, or split by size. A queue is what keeps the user’s “post” request from waiting on fan-out, and message queues and event-driven architecture is the deeper version of that pattern.
Ranking should stay at a high level unless they ask for more. I’d split it into two stages. First, candidate generation: pull a few hundred post IDs from the precomputed timeline and from celebrity followees. Then a ranker orders that set. For a first pass, recency plus a few signals is enough: how often you interact with the author, post type, maybe a simple score. I would not invent click-through rates, and I would not drag a training pipeline onto the board. If they want the machine-learning version of this prompt, that’s a different interview; the machine learning system design post is a better starting point for that shape, still as interview prep, not a production recommender.
The feed the user sees is not the raw inbox. Hydration, ranking, and filters (blocks, mutes, deletions) happen on the way out. Precomputation is a starting set, not a promise that the stored order is final.
I’d put all three on the board, then pick the hybrid and say the cost: a merge step on read, and a threshold for who counts as a celebrity account.
Caching, sharding, and how a page of the feed is served
Now draw the simple version end to end: client, load balancer, stateless app servers, a post store, a follow graph, a timeline inbox sharded by the feed owner, a cache in front of the hot reads, and a queue for fan-out jobs. Get a path that works, then add a box only when a number forces it. The same caution shows up in system design mistakes to avoid.
A post request writes the post once, then, if the author is not a celebrity, enqueues fan-out work that appends the post ID to follower timelines. A feed request reads the caller’s timeline page, pulls recent posts from celebrity followees, hydrates post bodies, filters anything that should no longer appear, runs the lightweight ranker, and returns a page with a cursor.
Shard the timeline store by user_id, the person who owns the feed. The user is already on the request, so you can route without a secondary lookup. Shard the post store by post_id. Replication gives you read capacity and failover. A brand-new post may take a moment to appear in another region, which matches the consistency choice we made early. For the split itself, see database sharding and replication. The URL shortener walkthrough is a useful contrast: that design shards by a code in the request, and this one shards by the user who is reading.
I’d be specific about what is cached. The first page of a user’s timeline. Post bodies, because the same popular post is hydrated into many feeds. The follow graph for ordinary accounts. I’d be careful with celebrity follower lists: you do not want to load five million user IDs into one process because someone pressed post, which is another reason those accounts are pull-based here. A time-to-live plus invalidation on a new post is enough for a first pass. The caching strategies post covers the patterns and failure modes in more detail.
The failure mode I’d raise myself is a hot key. A celebrity post, or that author’s recent-post cache, can take traffic well out of proportion to “average posts per second.” Replicate that cache entry, keep a short in-process cache on the app servers, and don’t fan-out the author on write. Cache the merged candidate set for a short time so every scroll doesn’t rebuild it from scratch.
Pagination should be cursor-based. A cursor of (timestamp, post_id) is stable enough for this interview. Offset pagination (“page 20”) will drift as new posts arrive and as items are deleted. Keep timeline inboxes bounded: a few thousand recent IDs per user is plenty, with older history fetched from a slower store only if they scroll that far.
Deletions, blocks, and unfollows belong on the read path. If you already pushed a post ID into ten thousand inboxes, you will not finish a consistent delete across all of them before the next refresh. Mark the post as deleted, and drop it at hydration. If I blocked you, your posts should not appear even if a pointer is still in my inbox. That filter is cheaper than rewriting every timeline on every graph change.
The celebrity account is the number that decides fan-out, not the average posts-per-second figure.
Follow-up questions interviewers actually ask
The last ten minutes are usually pokes at this design, not a second prompt. Short spoken answers you can practice, all illustrative:
“A celebrity posts. What breaks first?” “If we fan-out on write, the follower list and a storm of timeline writes. In the hybrid, we don’t push that post into millions of inboxes. We write it once, cache the post, and mix it into followers’ feeds at read time.”
“Do you precompute the feed, or compute it when I open the app?” “Both. Ordinary follows are already in a timeline inbox. Celebrity follows are pulled when you read. I wouldn’t rebuild the whole feed from the follow graph on every open.”
“I delete a post, or someone blocks me. What happens?” “The post gets a deleted or hidden flag, and the read path drops it during hydration. I wouldn’t try to chase every inbox copy in the request. Blocks and unfollows are filters on the way out, plus we stop future fan-out.”
“How soon does a new post show up?” “I’d aim for a few seconds, not a hard worldwide instant. Fan-out jobs and cache fills take time, and a replica in another region may lag. If they insist it must appear immediately for every follower, I’d say what that costs: tighter replication, or waiting on more of the push work.”
“How do you paginate without repeating or skipping items?” “Cursor-based, with a timestamp and post ID, not an offset. The next request continues from that cursor. New posts can land at the top without shifting page 3. Deleted items are skipped at hydration, so the client may get slightly fewer items and still has a valid cursor.”
This prompt also sits on most “common questions” lists, including top FAANG system design questions. If they shrink the scale until there are no celebrity accounts, fan-out on write alone can be enough, and you should say that. The hybrid is a response to an uneven follow graph, not a required decoration.
Practice the talking version
A worked design on a blog is the easy half. In the room you still have to ask about celebrity accounts, pick fan-out on write versus read with a reason, and keep going when someone says “why not compute the whole feed on every request?”
OfferBull is an AI mock interview app for iOS and Android. A voice interviewer asks questions aloud. You answer by speaking. Paste a job description or upload a resume for tailored questions. Follow-ups based on what you said and what’s on the resume. While you practice, you get answer suggestions and STAR structures. English and Chinese. It’s for rehearsal before a design interview, not a helper during one.
FAQ
Is fan-out on write always the right pick? No. It’s a strong default when most accounts have a bounded follower count, because reads become cheap. It gets expensive for celebrity posts. I’d start there, then add a pull path for high-follower accounts.
How much ranking do I need in a 45-minute interview? Usually less than people think. Candidate generation plus recency and a few signals is enough for a first pass. Go deeper on a ranker only if they ask. Don’t spend the first 20 minutes on a training pipeline.
What should I cache? The first timeline page, post bodies, and ordinary follow lists. Be careful with huge follower lists. Cache is there to make the read path fast, not to hide a celebrity fan-out you shouldn’t be doing.
What if my interviewer wants a different scale? Redo the three or four numbers that change a decision, out loud. A million daily users with no huge accounts can live on a simpler push model. Hundreds of millions of daily users, with some accounts followed by a large fraction of the user base, makes the hybrid and the hot-key discussion the center of the interview.
Practice This Out Loud
Tonight, if you can: set a 45-minute timer, close the notes, and talk through this prompt from requirements to one deep dive and one failure mode. Record it on your phone. On playback, check two things only. Did you pick fan-out on write, on read, or a hybrid, and say the cost? Did you get to a celebrity or deletion discussion before the timer ended? Then run the same prompt in a voice mock that pushes back with follow-ups, and close the app before any real interview. → Practice Now
Take Control of Your Career Path:
- Official Site: www.offerbull.net/mock-interview
- iOS App: Download for iPhone/iPad
- Android App: Download for Android