Back to roadmap
Module 10 · End-to-End Design DrillsDay 09245 min

Drill: Twitter Feed

Fan-out on write vs read — and the celebrity problem.

Day 092

Drill: Twitter Feed

User
client
Tweet API
service
Kafka
queue
Fan-out worker
service
Timeline cache
cache
Signal path
Fan-out architecture with celebrity merge
User
client
flow
Tweet API
service
Tweet API
service
flow
Kafka
queue
Kafka
queue
flow
Fan-out worker
service
Memory hook

Twitter Feed: fan-out on write vs read

Mental model

compose the pieces into a design story

Design lens

Fan-out workers must scale with biggest follower counts.

Recall anchors
Fan-out writeFan-out readHybrid

Why it matters

Twitter-style timelines must serve reads at huge fan-out. Pure fan-out-on-write precomputes timelines per follower; fan-out-on-read computes on demand. Hybrid handles celebrities.

Deep dive

Fan-out-on-write: cheap reads, expensive writes for users with millions of followers.

Fan-out-on-read: cheap writes, expensive reads when many followees exist.

Hybrid: regular users get push fan-out; celebrities use read-time merge.

Cache hot timelines; regenerate via async job.

Demo / scenario

1B users, 10M tweets/day, 200B timeline reads/day.

  1. Tweet service writes to DB + Kafka.
  2. Fan-out worker pushes tweet IDs to follower timelines.
  3. Celebrities flagged → readers merge their tweets at read time.
  4. Timelines cached in Redis; replayable.

Tradeoffs

  • Fan-out workers must scale with biggest follower counts.
  • Hybrid edges add complexity.
  • Materialized timeline drift handled with periodic rebuild.

Diagram

User
Tweet API
Kafka
Fan-out worker
Timeline cache
Read service
Fan-out architecture with celebrity merge.

Mind map

Check yourself

Loading quiz…

Sources & further reading