A news feed looks like “show me recent posts from people I follow” — a SELECT ... WHERE author IN (…) ORDER BY time. At small scale that’s exactly right. At Instagram scale it’s impossible: a single feed load would fan out to hundreds of accounts, each with millions of posts, recomputed for every one of hundreds of millions of users, many times a day. So the real design question isn’t what’s in the feed — it’s when you assemble it.
There are two answers, and they’re mirror images. Push (fan-out on write): the moment you post, copy it into every follower’s precomputed feed — writes are expensive, reads are instant. Pull (fan-out on read): store the post once, and assemble each feed on demand when someone opens the app — writes are trivial, reads do all the work. Flip between them and watch the cost move:
Notice how push and pull are mirror images — one loads the write, the other the read. Hybrid keeps both bounded.
Push writes 180 rows now so reads are O(1). Fine for a normal account; reads are instant.
Post as the Celebrity
Now switch the author to the celebrity (40M followers) with push selected. One post = 40 million feed writes. That single account — the hot key — is why no real system pushes everything, and why the answer every interviewer is listening for is hybrid.
Why this is the whole system
- Push wins reads, loses on hot keys. Precomputed feeds make opening the app O(1) — perfect for the 99% of users. But a celebrity post triggers tens of millions of writes, and users who rarely log in get feeds computed they never read (wasted writes).
- Pull wins writes, loses on read latency. Storing once is cheap, but every feed load re-reads and merges every followed account — brutal for someone who follows thousands, and it hammers the same popular authors repeatedly.
- Hybrid takes the best of both. Push for normal accounts (fast reads for almost everyone), pull for the handful of celebrities (bounded writes), and merge the two at read time. That’s what production feeds actually do.
The members-only build takes it all the way: the precompute-feed architecture and the fan-out service (with async, batched code); the celebrity / hot-key problem and the exact hybrid that fixes it; ranking (why “reverse-chronological” became “scored,” and where that runs); pagination that survives a constantly-changing feed (cursors, not offsets); the caching tiers; how Twitter, Instagram, and LinkedIn each landed on a hybrid; and an interview challenge with a worked answer.
Keep reading with Premium
You've reached the members-only part of this deep-dive — the full implementation, the interactive ring simulator, and the step-by-step walkthrough. Unlock it with a membership.
Discussion
Loading the conversation…
Discussion
Loading the conversation…