Hybrid Fanout Strategy
What you'll learn: How to combine push and pull fanout models to handle both regular users and celebrities efficiently in a social media feed system.
The Core Idea
A hybrid fanout strategy intelligently switches between fanout-on-write (push) and fanout-on-read (pull) based on user characteristics, typically follower count. The key insight: most users benefit from pre-computed feeds (push), but celebrities with millions of followers would overwhelm the system if we tried pushing their posts to everyone at write-time.
How It Works
When a user publishes a post, the system checks their follower count:
-
Regular users (< threshold): Use fanout-on-write. The post is immediately pushed to all followers' pre-computed feeds. Fast reads, manageable writes.
-
Celebrities (> threshold): Use fanout-on-read. The post is stored centrally, and followers' feeds pull from celebrity accounts at read-time. This avoids writing millions of records.
-
Your feed: A blend of pre-computed posts (from regular users you follow) plus real-time queries (for celebrities you follow).
Real-World Example
Imagine you follow 500 people: 490 regular users and 10 celebrities. Your feed contains:
- 490 pre-pushed posts sitting in your timeline cache
- 10 celebrity posts fetched on-demand when you open the app
The system merges and sorts these sources, presenting a unified feed.
The Threshold Decision
The "celebrity threshold" (e.g., 1 million followers) is tunable based on:
- Write capacity
- Acceptable fanout latency
- Storage costs
Key Takeaway: A hybrid fanout strategy combines the read-speed benefits of push for regular users with the write-efficiency of pull for high-fanout accounts, solving the celebrity problem while maintaining feed performance for most users.