Case studies
Case study: news feed
How a home feed copes with fan-out, celebrities, ranking and deletes at hundreds of millions of users, and where the design gets hard.
A news feed (home timeline) shows a user recent posts from the people they follow, optionally ranked. At small scale it is a simple query. At hundreds of millions of daily users, the hard problem is not storing posts. It is fan-out: getting each new post in front of the right readers fast enough that opening the app feels instant.
Meta's early feed systems and Twitter's timeline service are the real-world references. Facebook's TAO paper describes the social graph store that sits under the feed. Once you can explain why "query every followee on read" fails at this scale, the rest of the design follows.
In an interview, lead with hybrid fan-out before drawing many boxes. Interviewers listen for the write-amplification math, the celebrity threshold, timelines as derived data, cursor pagination, and media kept off the database.
Concepts in this section
| Step | Concept | What it answers |
|---|---|---|
| 1 | Requirements and estimates | What must the feed do, and how big is it? |
| 2 | Fan-out on write and read | Where does the cost of delivering a post go? |
| 3 | Timeline storage | How is each user's list of posts stored and read? |
| 4 | Hybrid fan-out and celebrities | How do you handle an account with 100 million followers? |
| 5 | Feed ranking | How are candidates ordered, and how are repeats hidden? |
| 6 | Timeline consistency, deletes and blocks | What happens to posts that are deleted, blocked or muted? |
Common mistakes
- Designing pure push or pure pull. Push fails on celebrities, and pull fails at peak read volume. Propose the hybrid, then explain the threshold.
- Treating timelines as the source of truth. Timelines are derived data. Keep posts durable and rebuild timelines when needed.
- Walking the social graph on every feed load. Precompute timelines instead of joining the graph for each card.
- Ignoring fan-out lag. When the backlog grows, feeds go stale. Alert on lag, scale the workers, and shed backfill work first.
- Overloading one hot post key. A viral post can swamp one cache key. Replicate the post cache, serve media from a CDN, and avoid synchronous writes on every like.
Key takeaways
- Feed latency is a read-path requirement. Meet it with precomputed timelines.
- Fan-out cost, not storage, is the hard part. Do the write-amplification math early.
- Use hybrid fan-out: push for ordinary authors, and merge celebrity posts on read.
- Timelines store references. Post bodies come from a cache, and media from object storage and a CDN.
- Rank in stages, and keep seen state and diversity rules explicit.
Further learning
A Meta engineer's mock interview designing Twitter shows how hybrid fan-out is explained under time pressure.
Jordan Hashemi's "Design Twitter" walkthrough covers estimates and the push and pull trade-off clearly.
ByteByteGo blog (Alex Xu) covers fan-out and caching patterns that come up in interviews.
Start with requirements and estimates.
Related
Caching
Where to put a cache, how to read and write through it, how to size it from hit-rate math, and how to keep it from serving stale data or melting down.
Recommender systems
How feeds and stores pick a short list from millions of items. A cheap retrieval step, a careful ranker and business rules. Start here for the map.
Sharding and partitioning
Split data across machines by choosing a shard key, hashing or ranging it, routing requests, handling hot spots, resharding without downtime and generating IDs that stay unique.