SimuVedaSystem Design Lab Open in the lab

Design interviews / Advanced / 6 min

Design Twitter/X: fan-out on write or on read

Copy each post into followers’ timelines, or merge at read time. One celebrity post floods the queue; the hybrid fixes it.

Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.

In short

What it is
A home timeline is built either by copying each post into every follower’s cached feed (fan-out on write) or by merging followed accounts at read time.
Why it matters
Reads vastly outnumber posts and must be instant, but follower counts range from a few to tens of millions.
The trade-off
Fan-out on write gives fast reads but huge write bursts for celebrities; fan-out on read is cheap to post but slow to read.
Say it in an interview
"Hybrid: fan out on write into Redis timelines for normal users, merge celebrity posts at read time, and only keep timelines for recently active users."

Check yourself

What makes fan-out on write cheap for readers?

Answer: Each user’s timeline is precomputed in a cache, so a read is one lookup. The work is done once at post time; opening the app just reads the ready list.

Why is a celebrity post a problem for fan-out on write?

Answer: Millions of follower timelines must each get a copy, which floods the queue and delays everyone. Write cost grows with follower count; one post can mean millions of inserts.

How does the hybrid approach work?

Answer: Normal accounts are fanned out on write; posts of huge accounts are merged in at read time. Readers merge only the few celebrities they follow, so reads stay fast and writes stay bounded.

See it happen in the simulation →

twitternews feedfan-outtimelinecelebrity problemhybrid

More in design interviews