When someone with 200 followers posts, those 200 timelines must change somehow. You can write the post into every follower's feed at posting time (push, fan-out on write) or let each follower assemble their feed when they open the app (pull, fan-out on read). This is the central decision in news feed, Twitter and Instagram designs. This lesson does the math for both, shows where each breaks, and builds the hybrid that real systems use.
Detailed Notes
What Problem Are We Solving?
Fan-out means one event causing work for many recipients: one post, delivered to every follower. In a social app, a user opens the app and expects a feed (also called a timeline), a list of recent posts from the accounts they follow, in a second or less.
There are two places to do the fan-out work.
Push, or fan-out on write: when a user posts, the system immediately copies the post id into every follower's precomputed feed. Reading a feed is then a single lookup.
Pull, or fan-out on read: the post is stored once. When a user opens the app, the system looks up who they follow, fetches each followed account's recent posts and merges them by time.
Both give the same feed. The difference is when you pay: at write time or at read time. The numbers decide which hurts more.
text
Assumptions
300M users, 200M open the app daily, 20M posts per day
Average follower count: 200
A day is about 100,000 seconds; peak = 3x average
PUSH: every post is copied to 200 feeds
20M posts x 200 followers = 4 billion feed inserts per day
4B / 100,000 s = 40,000 inserts per second (120,000 at peak)
Reads: 200M users x 10 opens = 2B feed reads per day = 20,000 reads/s
Each read = 1 lookup of a precomputed list
PULL: nothing is copied at write time
Writes: 20M posts per day = 200 posts per second, trivial
Reads: 2B feed opens per day = 20,000 opens per second
Each open fetches posts from about 200 followed accounts
20,000 x 200 = 4 million account lookups per second (12M at peak)
Push shifts about 40,000 writes per second onto the background path to make 20,000 reads per second cheap. Pull does only 200 writes per second but pays 4 million lookups per second on the read path. Because feeds are read about 100 times more often than they are written (2B reads versus 20M posts), push does more total work per post but saves enormous work per read.
Then the celebrity problem breaks push:
text
A celebrity has 50M followers and posts once.
Push: 50M feed inserts for one post
At a 100,000 inserts/s fan-out budget: 50M / 100K = 500 seconds, about 8 minutes
-> followers see the post minutes late, and the queue is blocked for everyone else.
Fan-out on Write vs Fan-out on ReadComparison
Push
fan-out on write
1
Post is stored once
post store
2
Event goes to a queue
author does not wait
3
Workers copy the post id
into 200 follower feeds
4
Reader fetches one list
a few ms
Fast, simple reads
Smooth read latency
200x write amplification
Celebrity posts take minutes
Wasted work for inactive users
Best when reads dominate
Pull
fan-out on read
1
Post is stored once
indexed by author
2
Nothing else happens
200 writes per second
3
Reader loads follow list
about 200 accounts
4
Fetch and merge by time
about 200 lookups per open
Cheap writes, any follower count
Always fresh, no wasted work
4M lookups per second
Slow tail latency
Best when writes or follower counts are huge
Key point. Push moves cost to the write path (40,000 inserts/s). Pull moves cost to the read path (4M lookups/s).
Same feed, work done at different moments. Assumes 20M posts per day, 200 followers each, 2B feed opens per day.
Option 1: Push (fan-out on write)
How it works
A user publishes a post. The post service stores it once in a post store.
It publishes an event to a message queue (the queues lesson) so the user does not wait.
Fan-out workers read the event, look up the author's followers, and insert the post id into each follower's feed cache, typically a list per user kept in an in-memory store, trimmed to the latest 500 items.
When a follower opens the app, the feed service reads that list, fetches the post bodies by id and returns them.
The feed is therefore precomputed: the work was done before anyone asked.
Pros
Very fast reads. One list lookup. A feed loads in a few milliseconds, which matters because feeds are opened constantly.
Read path is simple and cheap. Easy to hit a p99 under 200 ms.
Smooths read load. Heavy work happens in background workers that can lag a little without breaking the page.
Cons
Write amplification. One post becomes 200 writes, and for large accounts millions.
Celebrity problem. Accounts with millions of followers produce huge bursts, delaying their posts and everyone else's.
Wasted work. Many followers are inactive. Pushing to 100M accounts that rarely log in burns storage and compute. A fix is to push only to recently active users.
Deletes and edits must touch every copy (or the copies hold ids only and bodies are fetched at read time, which is the standard approach).
Storage. 300M feeds x 500 post ids x 8 bytes = 1.2 TB of feed cache, affordable but real.
When to use it
Choose push when reads far outnumber writes, most authors have a modest follower count, and feeds must load very fast.
Realistic scenario. A photo-sharing app where the typical account has 200 followers and the top accounts have 20,000. A post fans out to 200 inserts in under a second. Opening the app reads one precomputed list. Users get a fast feed, and the fan-out cluster runs at a comfortable 40,000 inserts per second.
Option 2: Pull (fan-out on read)
How it works
A user publishes a post. It is saved once, indexed by author and time.
When a user opens the app, the feed service reads their follow list (200 accounts), requests each author's latest posts in parallel, then merges the results by timestamp and returns the top 20.
A cache of recent posts per author reduces database hits.
Pros
Cheap, instant writes. A post is one write, no matter the follower count.
No celebrity problem on write. A 50M-follower account costs the same to publish as anyone.
Always fresh. The feed reflects the newest data, and follows, unfollows and deletes apply immediately.
No wasted work. Nothing is computed for people who never open the app.
Less storage. No per-user feed copies.
Cons
Slow, expensive reads. Each open means about 200 lookups plus a merge. At 20,000 opens per second that is 4 million lookups per second.
Tail latency. The feed is as slow as the slowest of the 200 lookups. With 200 parallel calls, even a 1% chance of one being slow means most opens hit a slow call.
Hot authors. Everyone reading a celebrity's latest posts hammers the same keys, so you need caching.
When to use it
Choose pull when writes are heavy or follower counts are huge, feeds are opened rarely, freshness matters more than speed, or the follow graph is small.
Realistic scenario. An internal company news tool has 20,000 users, each following 30 channels, with feeds opened a few times a day. Pull is simple: 30 lookups per open at about 1 request per second overall. Building fan-out workers and feed caches would be wasted effort.
The hybrid: push for most users, pull for celebrities
Large systems combine both with a follower-count threshold (for example 100,000).
Normal accounts (below the threshold): push their posts into followers' feed caches.
Celebrity accounts (above it): do not fan out. Store the post once.
On read: the feed service takes the precomputed feed (pushed posts), then pulls the latest posts of the few celebrities this user follows, and merges the two lists.
A user follows maybe 5 celebrities, so a read does about 1 list lookup plus 5 author lookups instead of 200. Writes stay bounded because no post fans out to more than 100,000 feeds. Other refinements: push only to users active in the last 30 days, and rank the merged result with a scoring model.
Hybrid Feed: Push Normal Accounts, Pull CelebritiesArchitecture
Key point. A follower-count threshold keeps the fan-out bounded and the read path short.
Normal posts are pushed into feed caches. Celebrity posts are stored once and merged when the feed is read.
Interview Discussion
Run the same four steps every time.
Define the shape: follower distribution (average 200, a long tail of celebrities) and the read to write ratio (about 100 to 1).
Do the math for both: 40,000 inserts per second for push, 4 million lookups per second for pull.
Find the breaking case: a 50M-follower account takes 8 minutes to fan out.
Propose the hybrid with a threshold, and name what you would monitor: fan-out queue lag, feed read p99, cache memory.
Interview tip. Do not present push as "the right way" and stop. The interviewer is waiting for you to raise the celebrity case. If you do not, they will.
Interview discussion. "Feeds are read about 100 times more than written, so I'd precompute them with fan-out on write for ordinary accounts. For accounts above 100,000 followers I'd skip fan-out and merge their latest posts at read time. That keeps fan-out near 40,000 writes per second and reads to one cache lookup plus a handful of author lookups."
Trade-off thinking. Push trades write cost, storage and delay for fast reads. Pull trades read cost and latency for cheap writes and freshness. The hybrid pays each cost only for the users where it is small.
Final Takeaway
Choose push when reads dominate and follower counts are moderate: you precompute feeds and make reads one lookup. Choose pull when follower counts are huge, writes are heavy, or feeds are rarely opened: you store once and assemble on demand. Use the hybrid for real social products: push for normal accounts, pull for celebrities, merged at read time. Always back it with the fan-out numbers: followers per post x posts per day versus lookups per open x opens per second.