Problem Framing and the Fan-Out Architecture
~40 min read
Scoping the feed ranking problem, establishing scale assumptions, and solving the fan-out challenge: how posts reach users' feed caches before ranking can even begin.
Framing the Problem
A social feed ranking problem differs from content recommendation in three important ways:
- Network constraint: candidates come primarily from accounts the user follows, not the entire content catalog
- Time-sensitivity: posts about live events, news, and conversations are highly time-sensitive; a 48-hour-old post about a basketball game in progress is worthless
- User-generated content: quality varies enormously (spam to high-value expert posts) and there's no editorial curation layer
Scale assumptions (state these in the interview):
- 300M active users
- Average 500 follows per user
- Average 5 posts/day per active user (300M × 5 = 1.5B posts/day)
- 50K feed requests/second at peak
- Latency SLA: render first screen within 100ms
The Fan-Out Problem
When user A (with 10 million followers) posts, 10 million users need to potentially see this post in their feed. This creates a scalability challenge:
Option A — Fan-out on write (push model): When a post is created, immediately write a reference to it in each follower's feed cache.
User posts → Fan-out service → Write to Redis feed cache for each follower
10M followers × 1 post = 10M writes immediately
Feed read: just read user's pre-assembled cache (fast)
Problem: a celebrity posting generates 10M simultaneous Redis writes
Option B — Fan-out on read (pull model): At feed request time, fetch posts from all accounts the user follows.
User requests feed → Fetch timeline for each of 500 follows → Merge → Rank
Problem: merging 500 timelines at query time is slow (500 × index lookups)
Production solution: Hybrid fan-out:
- Regular users (< 100K followers): fan-out on write → pre-built feed cache
- Celebrity accounts (> 100K followers): fan-out on read at query time
- Threshold: determined by infrastructure cost; typically 10K-1M followers
Post created by regular user (1K followers):
→ Write to 1K follower caches immediately (manageable)
Post created by celebrity (10M followers):
→ Just store the post in a global index
→ At feed request time: check if user follows any celeb accounts → pull their posts
→ Merge with pre-assembled cache → rank all together
Candidate sources beyond follows:
Many platforms have expanded beyond 'only show posts from follows':
- Trending posts in topics the user engages with (two-tower retrieval)
- Posts liked/shared by people the user follows (second-degree signal)
- Recommended accounts ('you might also like') content
Mixing network + algorithmic sources: collect candidates from all sources, deduplicate, then rank them together with a unified scoring model.
💬 Deep Dive with AI
Key points
- •Fan-out on write is fast to read but creates massive write amplification for high-follower accounts; fan-out on read avoids write amplification but is slow for accounts with many follows
- •The hybrid approach (write for regular users, read for celebrities, with a follower count threshold) is the production standard for social feed systems
- •Algorithmic expansion (posts from beyond the user's follows) requires a separate candidate generation path, typically two-tower retrieval from a global post index