Case Studies
Design a News Feed
Show each user the latest posts from everyone they follow: fan-out on read is slow to load, fan-out on write melts down when a celebrity posts, and the hybrid most large networks use gets the best of both.
Advanced 4 min read· Updated 2026-11-18
What you will learn
- Compare fan-out on read (pull) and fan-out on write (push).
- See why accounts with millions of followers break push.
- Design the hybrid model and the feed storage behind it.
- Rank, paginate and cache feeds.
Before you start
Requirements
- Functional: users post; each user's home feed shows recent posts from accounts they follow, newest (or highest-ranked) first, paginated.
- Non-functional: loading a feed is fast (p99 < 300 ms); new posts appear for followers within seconds; reads vastly outnumber writes.
- Skew: most accounts have a few hundred followers; a few have tens of millions.
Back-of-the-envelope estimates
| Quantity | Assumption | Result |
|---|---|---|
| Feed loads | 300 M daily users × 10 loads | ~35,000 reads/s |
| Posts | 300 M × 0.5 posts | ~1,700 posts/s |
| Fan-out (push) | Average 200 followers | ~350,000 feed inserts/s |
| Celebrity post | 50 M followers | 50 M inserts for a single post |
Evolve the design
Stage 1 of 3
Fan-out on read
- Current architecture
- Loading a feed fetches recent posts from every followed account and merges them.
- Limitation
- Read cost grows with the number of accounts followed — and reads are the hot path.
- Bottleneck
- Read workers: 200 lookups per feed load saturate the service.
- Improvement
- Do the work once at write time instead of on every read.
- Performance impact
- Most feed loads time out.
- Complexity & operational cost
- Cheap writes, very expensive reads.
- Trade-off
- Always fresh, but the slow operation is the frequent one.
Loading simulation…
Feed storage
# Fan-out on write: add the post to each follower's feed, keep only the newest 800 ids.
ZADD feed:{user_42} 1763459000 post:9001
ZREMRANGEBYRANK feed:{user_42} 0 -801
# Read: newest 20 ids, then batch-fetch post bodies (cached) and merge in celebrity posts.
ZREVRANGEBYSCORE feed:{user_42} +inf -inf LIMIT 0 20- Store ids, not posts: feeds hold post ids; post bodies live once in a post store and cache.
- Paginate with a cursor (score/time of the last item), not offsets — feeds change while you scroll.
- Skip inactive users during fan-out and rebuild their feed on next login.
- Ranking happens at read time over a candidate set (recent ids + celebrity posts + recommendations).
Trade-offs
| Benefits | Costs | |
|---|---|---|
| Pull | No write amplification; always fresh. | Expensive reads on the hottest path. |
| Push | Reads are a single lookup. | Write amplification and huge backlogs for big accounts. |
| Hybrid | Bounded fan-out with fast reads. | More complexity and a threshold to tune. |
Interview checklist
- Compute the read/write ratio and follower skew first.
- Explain pull vs push, then the celebrity problem, then hybrid.
- Describe feed storage (ids in sorted sets), post store and caches.
- Mention cursor pagination, ranking and handling inactive users.
Further reading
Related topics
Design to Scale
Caching Strategies
Put a cache in front of a struggling database: how cache-aside works, what drives the hit ratio, how to keep data fresh, and how to survive the moment the cache goes cold.
Microservice Patterns
Queue-Based Load Leveling
Put a queue between a bursty producer and a system that cannot scale, so the system works at a steady pace it can sustain while the queue absorbs the peaks.
Design to Scale
Database Sharding
Spread data across several independent databases by a shard key to scale writes and storage beyond one machine — and avoid the classic traps: hot shards, cross-shard queries and painful resharding.
Microservice Patterns
CQRS
Separate the model that changes data from the model that reads it, so each can be designed and scaled for its job — and learn to live with read models that are slightly behind.
Design to Scale
Kafka Partitioning
Partitions are Kafka's unit of parallelism and ordering. Choose the message key and partition count well and consumers scale linearly; choose badly and one hot partition holds everything back.