Fanout-on-Write (Push Model)
You'll learn how pre-computing feeds at write-time enables blazing-fast reads for social media users.
What Is Fanout-on-Write?
In the push model, when a user publishes a post, the system immediately writes that post to the pre-computed feeds of all their followers. Instead of waiting until someone requests their feed (and then figuring out what to show), you do the heavy lifting upfront during the write operation.
Think of it like a newspaper delivery service: when the morning edition is published, delivery workers immediately distribute copies to every subscriber's doorstep. When subscribers wake up, their newspaper is already waiting—no need to travel to the printing press.
How It Works
- User creates a post → triggers fanout process
- System identifies all followers (from the follow graph)
- Write operation copies/references the post into each follower's feed cache or timeline table
- Followers read from pre-built feeds → instant, database-friendly reads
Why Use This Approach?
Fast reads: When Alice opens her feed, it's already assembled. No joins, no complex queries—just a simple retrieval.
Predictable read performance: Read latency is constant regardless of how many people a user follows.
The Trade-off
The write becomes expensive, especially for users with millions of followers (the "celebrity problem"). Publishing one post might trigger millions of feed insertions, creating massive write amplification.
Key Takeaway: Fanout-on-write optimizes for read performance by pre-computing feeds during post creation, trading write complexity for blazing-fast, predictable feed retrieval—but struggles with high-follower accounts.