The shape
One producer creates an item, and many consumers need to see it. Somewhere between the producer and the consumers, the item has to be copied into whatever each consumer reads from. The only decision is when that copying happens, and there are two answers.
Fanout on write does the copying when the item is created. When a post arrives, the system appends its id to a list kept for each follower, one append per follower. That list is the follower's timeline. To read, the follower does one range read: a single request for the newest entries of their own timeline. A read does not get much cheaper than that. You paid for it at write time, once per consumer.
Fanout on read does the copying when somebody looks. At write time the system only stores the item. To read, it goes to every producer this consumer follows, pulls their recent items, and merges them. A write costs nothing extra. A read costs one query per producer the consumer follows, so reads get slower the more accounts a consumer follows.
In general terms, you are choosing whether the cost lands on the producer or on the consumer. That is why the same choice turns up in places that look nothing like a social feed. A notification service makes it when it decides whether to build each user's inbox up front. A chat system makes it when it decides whether a group message writes N copies, or writes one copy that is read N times. A search index makes a version of it when it decides between updating documents as they change and merging segments at query time. Any cache that can be filled on write or filled on a miss makes it too.
The answer is almost never "pick one". The answer is a threshold, and most of the work is finding it.
The mechanism
Both paths have the same three parts: an item, a set of consumers, and a place each consumer reads from. They differ in which side fills that place.
The cost of each path fits on one line. For a given producer:
fanout on write cost = followers x (writes per item)
fanout on read cost = followers x (feed opens per follower)
For a normal account, the two costs are far apart. Someone with 300 followers who posts twice a day costs 600 list appends a day. With fanout on read instead, each of those 300 followers has to merge this account's posts into every feed they open, many times a day. Fanout on write wins by about 200 times, as the worksheet below works out, because in almost every system where this pattern appears, reads happen far more often than writes.
At the top end, the picture looks different. An account with 100 million followers costs 100 million appends for one item. A single write has become the size of a batch job. The readers who want that item are the same hundred million followers, and they open the app on their own schedule anyway. With fanout on read, each of their feed opens merges one extra list.
So the standard answer is the hybrid. Ordinary producers fan out on write. For the small set of very large producers, the system skips fanout and merges their recent items in at read time. Each consumer's read becomes a cheap range read of their own timeline, plus a small merge of the few large accounts they follow.
The threshold is the follower count above which an account stops fanning out on write. You can compute it for your own system rather than copying a number somebody else uses.
The hybrid is not adopted because fanout on write gets more expensive in total. Per follower, it stays cheaper at every scale. The worksheet below shows it staying cheaper by the same 200x whether the account has 300 followers or 100 million. The two costs never cross.
The hybrid is forced by something else. One write turns into 100 million appends, and all of them have to finish before the last follower can see the item. That is a latency problem and a burst-capacity problem, and a model of cost per follower shows neither of them.
Take a system with:
posts per producer per day 2
feed opens per consumer per day 20
cost of one timeline append ~0.1 ms
cost of one extra list merged at read ~2.0 ms
Fanout on write, per producer per day:
followers x 2 x 0.1 ms
Fanout on read for that producer, per day:
followers x 20 x 2.0 ms (each follower merges
this one extra list,
on every feed open)
→ write 0.2 ms per follower per day
→ read 40.0 ms per follower per day
──────────────────────────────────────────────
Writing is 200x cheaper per follower, and it stays
200x cheaper at 300 followers and at 100 million.
Cost per follower never picks the hybrid for you.There are three problems in all, and a cost per follower shows none of them.
- Latency. The last follower cannot see the item until every append in the batch is done. That can take minutes.
- Burst capacity. The fanout tier is the set of workers that do the appends. You have to size it for the moment a celebrity posts, not for the average post rate, and that peak is thousands of times the average.
- Wasted work. Most of those hundred million timelines belong to people who will not open the app today. You wrote into all of them anyway.
How to tell you have this problem
You have this problem whenever one write has to become visible in many places. There are three symptoms, and each one tells you which side you are on.
Writes are slow or spiky, and the spikes come from specific users. Post-to-visible latency is the time from somebody creating a post to the post showing up in the last follower's feed. Plot it with follower count along the bottom. If the slowest 1 percent of posts (the p99) come almost entirely from a handful of very large accounts, you are fanning out on write past the point where it works.
Reads are slow, and the latency grows with how many accounts the user follows. Plot feed load time against the number of accounts the consumer follows. If that line slopes upward, you are fanning out on read. The people who follow the most accounts get the slowest feeds, and that is the wrong way round.
Your fanout queue depth jumps instead of staying steady. Queue depth is the number of appends waiting for a worker. If the depth is steady but high, you need more workers for the average rate, and that is ordinary sizing. If it jumps and takes minutes to come back down, single writes are turning into large batches.
In most systems, one query settles it. Count followers per account, biggest first: select count(*) from follows group by followee_id order by 1 desc limit 100. If the top of that list is 10,000 to 100,000 times the median, you need the hybrid. How fast the counts fall from the top of the list tells you where to put the threshold.
What it costs
There are four costs, and the write volume is not one of them.
Two code paths that must produce the same results. A consumer's feed now comes from two places: the timeline written in advance, and the items merged in live at read time. The two paths can disagree about ordering, about which duplicates to drop, and about what to filter out. Every feature you add later, such as ranking, blocking or muting, gets built on both paths, and the two have to agree. That cost stays for as long as the hybrid does.
The threshold is a config value, and crossing it changes behaviour all at once. An account that crosses it switches from one path to the other between one post and the next. If the switch is handled carelessly, there is a window where the account's recent items are in some timelines and not in others. A follower sees an item vanish and come back. So treat the crossing as a step you plan and run, not something that just happens.
A timeline written in advance is a cache, and it can be wrong. Deletes, blocks, privacy changes and edits all have to reach data you already copied. Most systems handle this by filtering at read time instead of rewriting timelines. That moves work back to the read side, and the read side is the one you were trying to keep cheap.
Storage for something most people will not read. Fanout on write fills the timelines of people who are not using the app. Two limits are standard: a cap on each timeline's length, and skipping anyone who has not opened the app in N days. Each one needs a fallback path, for a reader who scrolls past the cap and for a skipped user who comes back.
Where it shows up in the course
| article | the form it takes there |
|---|---|
| Design a Leaderboard / Ranking Service | friends boards are built at read time from 50 scores, because scores change far more often than anyone looks |
| Design Google Docs (Collaborative Editing) | keystrokes are pushed to up to 100 people in the live session; everyone past the cap fetches a published snapshot |
| Dropbox and Google Drive | a shared folder is one journal every member reads; only the small hint fans out on write |
| timelines hold post ids rather than posts, so the fanout cost is set by id size and the photo never enters the serving path | |
| News Feed and Timeline | the full derivation, including where the threshold falls and why inactive followers are skipped too |
| Notification Service | personal messages get one inbox row each, while a campaign is stored once and merged into each inbox on read |
| Push Notification Delivery | the push fans out on write, one message per device, while the in-app record of a broadcast can fan out on read |
| Search Autocomplete | a top-10 list stored at every trie node is work done at build time; the edge cache keeps the read-time answer for the prefixes people actually type |
| WebSockets, SSE and Polling | live comments for a million viewers, where pushing into every connection gives way to one shared object read through a CDN |
| WhatsApp and Chat Systems | group delivery, and the size above which a group stops being a chat and becomes a broadcast |
| Live Comments and Reactions | one comment for millions of viewers fans out in two steps: one copy per gateway, then one write per local connection |
Getting it wrong
Treating it as a binary choice. Almost every real system uses both. A design that picks one and defends it has usually not looked at the follower distribution.
Putting the item in the timeline instead of the id. A timeline holds ids that point to items. If you copy the item itself, storage grows by a factor of the average follower count, and every edit becomes a rewrite of millions of rows.
Sizing the fanout tier for the average. The average post rate does not decide the size. The largest producer you still fan out to does, and that producer sits just under the threshold you chose. So the threshold is also a capacity decision.
Forgetting that the read path still merges. In the hybrid, every read combines the timeline written in advance with live queries for the large accounts. If nothing limits that merge, a user who follows 2,000 large accounts gets the slow path.
Letting the threshold be implicit. "We handle celebrities differently" is not a design. The number, and what happens to an account the day it crosses, is the design.
Assuming the hybrid is about cost. It is about latency, burst capacity and wasted work. Per follower, fanout on write stays cheaper at every scale. If you say so in the interview, it shows you did the arithmetic rather than repeating what everybody says.