Scope
Functional
- Post short text (+ media). Follow/unfollow.
- Home timeline: posts from followed accounts, ranked, paginated.
- User timeline: one user's own posts.
Non-functional
- Home timeline p99 < 200 ms. New posts visible to followers within ~5 s.
- 300M DAU, read-heavy.
Size
- Posts: 300M × 0.5/day → 150M/day ≈ 1,700 posts/s (peak ~5k).
- Timeline reads: 300M × 20/day → 6B/day ≈ 70k/s (peak ~200k).
- Average 200 followers per poster → fan-out of 1,700 × 200 = 340k timeline inserts/s.
- Some accounts have 50M+ followers: one post would mean 50M inserts.
APIs and data
POST /v1/posts {text, media_ids}
GET /v1/timeline/home?cursor=&limit=20
GET /v1/users/{id}/posts?cursor=
POST /v1/users/{id}/follow- Posts (sharded by
post_id, Snowflake IDs give time order). - Follow graph:
followers(user_id)andfollowing(user_id)tables, sharded by user. - Timeline cache: Redis list/sorted set per user of the latest ~800 post IDs.
Fan-out models
| Fan-out on write (push) | Fan-out on read (pull) | |
|---|---|---|
| On post | Insert post ID into every follower's timeline | Just store the post |
| On read | Read one precomputed list: fast | Merge recent posts of everyone you follow: slow |
| Cost | Huge for celebrities; wasted on inactive users | Expensive reads for users following thousands |
Choice: hybrid. Push for normal accounts; pull for celebrities (e.g. > 1M followers). At read time, merge the precomputed timeline with recent posts from the few celebrities the user follows.
The 30-second summary
"Hybrid fan-out: posts from normal accounts are pushed asynchronously into per-user Redis timelines of post IDs; celebrity posts are pulled and merged at read time. Reads fetch IDs, hydrate from a post cache, and optionally rank the top few hundred candidates within a strict latency budget. Inactive users' timelines are rebuilt on demand."
Follow-up questions the interviewer may ask
- How do you handle a celebrity with 50M followers posting?
- How do you rank instead of showing reverse-chronological?
- A user unfollows someone. Must their posts vanish immediately?
- How do you paginate a feed that changes while scrolling?
Model answers to each of these are in the book.