News feed system design: fan-out, celebrities and ranking
How to design a social news feed (Facebook, Instagram, X, LinkedIn) in real interview order: timeline inserts and the biggest account as the numbers that matter, a light API that posts before fan-out and pages by cursor, a post store, social graph, fan-out queue, timeline cache, feed service and ranker built in passes, one post walked from upload to a follower's screen, a lab on the celebrity threshold between push and pull, an explainer on how a ranked feed scores two posts, a lab on ranking inside a latency budget, a demo of offsets vs cursors while new posts arrive, where deletes and blocks are enforced, and what happens when each part fails.
The 1-minute answer
How this page follows the interview
Each phase is a section below, in the order you'd present it. Click a phase for what to say, what to write, and the trap.
This is a generic news feed (the Facebook, Instagram, X or LinkedIn home feed), built from what those companies have published. Fan-out and paging were introduced in Foundations F16 (search, feeds and geo); caching, queues and sharding in F06, F07 and F10. Recommendation models in depth come later in the AI / ML track.
Requirements and numbers
Agree what's strict and what can bend, then size both paths. Posts are cheap; fan-out multiplies them by followers, and one huge account multiplies them by millions. Change any input: each number comes with the decision it forces.
Functional
- Create a post with text and media
- Follow and unfollow accounts
- See a home feed of followed accounts (ranked, with a newest-first option)
- Scroll through it page by page
- Like, comment, and see counts
Non-functional
- Feed page under 250 ms at p99 (server)
- A new post reaches followers within a few seconds
- Always show something, even if older or unranked
- Deleted, blocked and private posts never shown to the wrong person
- Accounts can have anything from 0 to 100 million followers
Out of scope (say it)
Messaging, search, notifications, the ads auction, how recommendation models are trained.
Capacity calculator
Every input is an assumption 🔶: say it out loud. Anchors: about 500 million posts a day, 5 billion ranking runs a day, about 1,500 candidates per request and 150 billion posts served a day on Twitter in 2023 ✅ Twitter 2023; timelines of 800 entries in 3 copies, kept only for users active in 30 days ✅ Twitter 2013 (3rd party). Users, follows and the peak factor are teaching values.
- A day is 86,400 seconds. Divide daily totals by it, then multiply by the peak factor.
- Writes are multiplied. Posts/s × followers × share active = timeline inserts/s.
- Size the extreme account on its own. One post × its followers is the number that breaks pure push.
Core entities and the API
A handful of calls. What they listen for: posting returns before fan-out, the feed comes back hydrated, and pages use an opaque cursor, not an offset.
| Entity | Key fields | Note |
|---|
Why the cursor matters, with a demo of offsets going wrong, is in the third deep dive below.
High-level design
Build it in passes and say why each box exists. Click any box to see what it does, what it owns, what's inside it and what you'd watch.
Walk one post, box by box
Priya posts a photo from her cousin's sangeet; she has 912 followers. Arjun, one of them, opens the app a minute later. He also follows nine big accounts that aren't fanned out. Each step lights up the path and shows what goes over the wire, what's stored and how long it takes.
Arrows show who calls whom, and the numbers give the order. Replies go back along the same line.
Data and database choices
One copy of each post, edges in both directions, and timelines that are only a cache of ids: if you lose them, you can rebuild them.
| Data | Pick | Considered | Why not those |
|---|
The code to know: fan-out and the read
-- Fan-out worker, for one page of followers (pipelined per shard).
-- Illustrative; no company's real code.
for f in followers_page(author, after=cursor, limit=1000):
if f.last_active_at < now() - 30 days: continue -- rebuilt on login
LPUSH tl:{f.id} post_id
LTRIM tl:{f.id} 0 799 -- keep 800 ids
-- Feed read for one user.
ids = LRANGE tl:{user} 0 799 -- one call
ids += MGET recent:{a} for a in followees_above_threshold(user)
page = rank(ids) |> drop(deleted, blocked, seen) |> take(30)
posts = MGET post:{id} for id in page -- hydratePseudocode with Redis commands. 🧭
Why this shape works
- A capped list per user. LPUSH then LTRIM keeps the newest 800; trimming one element is O(1). ✅ Redis docs
- Only active users. Users seen in the last 30 days keep a timeline in memory; others are rebuilt when they come back. ✅ Twitter 2013 (3rd party)
- Edges in time order. Facebook's TAO keeps each association list newest first and pages through it; it serves a billion reads a second. ✅ TAO 2013
- Ids, not posts. An edit or delete changes one row; every read re-checks it. 🧭
More database questions
Deep dive: who gets pushed (the celebrity threshold)
Push makes reads one lookup but multiplies every post by its followers. Pull makes writes free but makes every read a merge. Pick a follower threshold: push below it, pull above it. Follower counts follow a power law, so a few accounts hold a big share of all follows. Pick a preset, then change the numbers.
Log scales. Ink: timeline inserts per second (push cost), with the fleet's limit dashed. Apricot: reads of pulled accounts' lists per second (pull cost). Red band: thresholds where the biggest pushed post misses the lag target; grey band: too many merges per feed open. The marker is your threshold. Followers per account are a Pareto tail with index α, scaled so the average equals the follows; share of follows to accounts above t = (t ÷ xm)^(1−α). Teaching numbers. 🧭
What the lab computes
- Inserts/s = posts/s × follows × (1 − share pulled) × share active. 🧭
- Worst lag = followers of the biggest pushed account × share active ÷ inserts/s one post can get. Twitter's 2013 figures: about 3.5 s for 1 million followers at p50, a 5 s target. ✅ Twitter 2013 (3rd party)
- Merges per open = follows × share pulled: the big accounts the feed service must read and merge on every request. 🧭
What companies chose
Twitter, 2013: push to timelines of 800 ids in Redis, 3 copies; posts from accounts with tens of millions of followers could take up to 5 minutes, so the plan was to merge them at read time. ✅ Twitter 2013 (3rd party)
LinkedIn, 2016: pull. Push stored "62 times" more data, and the feed ranks tens of thousands of records per request anyway, at about 140 ms p99. ✅ LinkedIn 2016
Deep dive: ranking inside a latency budget
A ranked feed is a funnel: gather many candidates cheaply, score a few hundred expensively, and finish inside the budget. First, how one score is made; then the lab that sizes the funnel.
How two posts are scored
The heavy model predicts the chance of each action; the score is a weighted sum, with negative weights for hides, then a freshness decay. Change the weights (what the product optimises for) and watch the order flip.
| Term | A | B |
|---|
What's public
- Facebook predicts several outcomes per post and combines them "in a linear way"; pass 0 picks about 500 posts, pass 1 scores each, pass 2 adds diversity. ✅ Meta 2021
- Instagram Explore: Expected value = W_click × P(click) + W_like × P(like) − W_see_less × P(see less) + … ✅ Meta 2023
- Instagram Feed looks most closely at five predictions: a few seconds spent, comment, like, share, tap the profile. ✅ Instagram 2023
- Twitter, 2023: about 1,500 candidates, a ~48M-parameter network with ten engagement labels, under 1.5 s on average. ✅ Twitter 2023
The weights and probabilities in this explainer are made up for teaching. 🧭
The ranking lab
p99 per stage, added up (an upper bound; stages run one after another). A stage with parallel calls waits for the slowest: its p99 is one call's quantile at 0.99^(1/n), with calls log-normal from the median and p99 you set. Teaching numbers. 🧭
Deep dive: deletes, blocks and new posts while you scroll
Timelines hold ids that were pushed minutes or days ago. So every rule about who may see what is checked again at read time, and paging must not repeat or skip posts while new ones arrive.
Paging while new posts arrive
Read page 1 (5 posts), let new posts arrive, then ask for page 2. Pick how page 2 is asked for.
Post ids are time-ordered (bigger = newer). Red: shown twice; struck out: deleted, dropped at hydrate. 🧭
Where each rule is enforced
| Rule | At write (fan-out) | At read (every page) |
|---|
A post's lifecycle
A post moves from written to fanned out to in feeds, and may be edited, deleted or taken down while copies of its id sit in millions of timelines. Click events to move it; ones that can't happen from the current state are disabled. Each event shows what fires across the system.
Edge cases interviewers love
Failure, monitoring and recovery
A feed fails loudly on the read path (slow or empty pages) and quietly on the write path (posts that arrive late). Click a box to take it down: red is the failed part, amber is its blast radius. Each answer covers impact, degraded mode, the alert, automatic and manual recovery, and how you'd trace it.
Tracing it back: a normal feed load vs a bad one
Every span carries the request id and user id. Times are seconds from the request. In the bad trace a timeline shard had just failed over, the user follows 60 pulled accounts, and the heavy ranker timed out, so the feed fell back to the light score.
How one failure becomes three
What you'd alert on (SLOs)
| Signal | Target | Alert |
|---|
Big-night playbook
The toolkit
Name the technique, then say where it goes in this design.
Making it fast, and who owns what
A page is a few milliseconds of cache reads and most of the budget goes to ranking; delivery to followers is measured in seconds. Bars are sizing estimates, not measured figures, except where cited.
| Team | Owns | Paged when… |
|---|
Senior follow-ups beyond the happy path
Interviewers pick from these themes once the design is on the board. Have one concrete answer per theme, tied to this design.
Practice ladder
Real interviews go level by level. Answer out loud before opening each one. Levels 6–7 are where Senior becomes Staff.
Sources
- Twitter's recommendation algorithm, Twitter Engineering (31 Mar 2023)
- The architecture Twitter uses to deal with 150M active users, High Scalability (third party, summary of Raffi Krikorian's QCon talk, 8 Jul 2013)
- Timelines at Scale, Raffi Krikorian, QCon San Francisco 2012, InfoQ (3 Apr 2013)
- FollowFeed: LinkedIn's feed made faster and smarter, LinkedIn Engineering (31 Mar 2016)
- Building a dynamic and responsive Pinterest, Pinterest Engineering (20 Sep 2018)
- TAO: Facebook's distributed data store for the social graph, Bronson et al., USENIX ATC (2013)
- How machine learning powers Facebook's News Feed ranking algorithm, Engineering at Meta (26 Jan 2021)
- Scaling the Instagram Explore recommendations system, Engineering at Meta (9 Aug 2023)
- Instagram ranking explained, Adam Mosseri (31 May 2023)
- Evolving API pagination at Slack, Slack Engineering (15 Aug 2017)
- LTRIM, Redis documentation (checked Oct 2026)
- Facebook news feed problem breakdown, Hello Interview (third party, used to cross-check interview expectations)
Checked October 2026. Scale anchors are Twitter's own March 2023 post on its recommendation algorithm (about 500 million posts a day, 5 billion ranking runs a day, about 1,500 candidates, a ~48M-parameter model, under 1.5 s on average, about half followed and half recommended) and a July 2013 High Scalability summary of Raffi Krikorian's QCon talk (third party: 300K timeline reads a second, 800-entry Redis timelines in 3 copies, fan-out only to users active in 30 days, a 5-second target, up to 5 minutes for a 31-million-follower account). LinkedIn's FollowFeed post (March 2016) is the pull-model counterpoint; Pinterest's September 2018 post explains why write-time scoring was dropped; Facebook's TAO paper (USENIX ATC 2013) covers the social graph. Ranking is from Meta's engineering posts (News Feed, January 2021; Instagram Explore, August 2023) and Instagram's ranking explainer (May 2023). Cursors are from Slack Engineering (2017); capped lists from Redis's LTRIM docs. No company publishes its current fan-out threshold, timeline sizes or ranking weights, so those are tagged as interview choices; the scoring explainer's weights are made up. Hello Interview is a third-party prep site, used only to cross-check what interviewers expect. All labs use rounded teaching values.
System Design Mastermind · Classics
Series homeAll of Classics
6 published · 4 comingThe problems almost every loop draws from.
Uber system design, reverse-engineered: from tap to pickup
In-memory geo index sharded by map cell → rank nearby drivers by road ETA → offer to one driver with a 15 s timeout → accept with compare-and-set → push updates to both apps.
Rate limiter system design: fair limits at a million requests a second
Check every request once in the API gateway → one atomic Lua script per request on the caller's shard of a sharded Redis (token bucket for per-second, window for per-day) → 429 + Retry-After, or forward with RateLimit headers → local cache for keys already over → each rule fails open or closed on purpose.
WhatsApp system design: chat, offline delivery and the three ticks
One long-lived encrypted connection per device → the chat server stores a copy per recipient device in a replicated offline queue, then acks (✓) → session lookup, forward or push → the device saves and acks, the copy is deleted (✓✓) → a read receipt when opened. Client-made ids and dedupe at both ends, backoff with jitter on reconnect, Sender Keys for groups.
Ticketmaster system design: selling seats without double-booking
Cached reads for browsing → a seat inventory with one row per seat, sharded by event → a hold is one conditional UPDATE (only if free or expired) with a 10-minute timer → pay with a client-made idempotency key → confirm only if the hold is still yours, plus an outbox for tickets. A waiting room admits fans at the rate booking can serve.
News feed system design: fan-out, celebrities and ranking
Write each post once → fan-out workers push its id into active followers' capped Redis timelines → accounts above ~1M followers are merged at read time instead → the feed service gathers ~1,500 candidates, a light model trims them, a heavy model predicts actions, a weighted sum orders them → deletes and blocks are checked at read time, pages use a cursor.
Notification system design: push, email and SMS without spam, drops or duplicates
One Notify API with an idempotency key → a router checks dedupe, preferences, caps and quiet hours, picks live devices → per-channel queues with a transactional lane apart from bulk → workers call APNs, FCM, email and SMS with priority, expiry and a collapse id, retry 429s with backoff and delete dead tokens → campaigns paced below the provider quota, OTPs fall back to SMS.