Social & Feeds
News Feed / Timeline System
Deliver a personalized, near-real-time feed of posts from accounts a user follows, at billions-of-users scale.
Scale to anchor on
~3B DAU, p50 read latency < 200 ms, fan-out from a celebrity post can reach 100M+ followers, 100k+ writes/sec at peak.
Requirements
Functional
- Show recent posts from followed accounts, ranked by relevance.
- Support text, image, and video posts.
- Read-your-own-write consistency.
- Mark posts as seen / unseen across devices.
Non-functional
- Low read latency at high QPS.
- Graceful handling of celebrity fan-out.
- Eventual consistency acceptable across followers.
- Cost per impression dominates infra economics.
High-level architecture
Hybrid fan-out: write into inboxes for normal users, query-time merge for celebrities. A ranking layer reorders the candidate set before serving. Caches sit in front of inbox stores and ranking signals.
Components
Post service
Stores posts, emits events to fan-out workers.
Fan-out service
Pushes post IDs into follower inboxes; routes celebrities to pull-on-read path.
Inbox store
Per-user list of candidate post IDs with TTL and bounded size.
Ranking service
Two-tower retrieval + heavy ranker for ordering and diversity constraints.
Edge cache
CDN-level cache for media; in-memory cache for the rendered feed page.
Key decisions
Hybrid fan-out (push for tail, pull for celebrities).
Pure push collapses on viral accounts; pure pull blows the read budget for normal feeds. Hybrid splits cost where it belongs.
Inbox size bounded with TTL.
Storage cost otherwise grows linearly with time per user; an unbounded inbox is also unusable on the read path.
Ranking after retrieval, not before.
Retrieval owns recall; ranking owns ordering. Mixing them couples two evolutions that should change at different cadences.
Eventual consistency for follower visibility.
Strict consistency at this scale is uneconomic; read-your-own-write is achieved with a small cache layer on the write path.
Pitfalls
- Designing for the median user and crashing on celebrities.
- Synchronous fan-out at write time: viral posts page the on-call.
- Counting on a single ranking model — A/B infrastructure is part of the architecture, not an afterthought.
- Forgetting the read-your-own-write story until an interviewer probes it.
Follow-up questions
- Where do you draw the celebrity threshold and how do you change it dynamically?
- How is read-your-own-write guaranteed when fan-out is async?
- How would you A/B test a new ranking model safely at this scale?
- What's the operational story for a post going viral mid-flight?