Social news feed
The hybrid feed: fan-out-on-write materializes timelines for normal users, celebrities are merged at read time, and a stampede-protected cache keeps hot feeds cheap.
What this design does
Pure fan-out-on-write dies the day someone gets 40M followers — one post becomes 40M timeline writes. Pure fan-out-on-read dies for everyone else — every feed load recomputes the world. Real feeds are hybrid: normal authors fan out to materialized per-user timelines at write time; celebrity posts are pulled and merged at read time; and a cache with stampede protection stands in front of it all so a viral moment doesn't become a database incident.
The patterns it composes
- Fan-out-on-write — normal posts append into each follower's materialized timeline
- Fan-out-on-read (celebrities) — mega-authors are merged at read time — never 40M writes
- Materialized view (timelines) — the feed is precomputed; reading it is a key lookup
- Cache stampede protection — probabilistic early expiry — one refill, not a thundering herd
- Push-notification fanout — mentions and DMs notify out-of-band of the feed itself
Import it, attach your own numbers, and verify the design against failures — or read the engineering notes.