← Back to Distributed Systems

Feed Fanout

Distributed SystemsSenior

The Question

What is feed fanout and what are the push vs pull approaches?

What a Strong Answer Covers

  • Push vs pull tradeoffs
  • hybrid for celebrities
  • Redis sorted set.

Senior-Level Answer

Feed fanout is the mechanism by which a post from one user is delivered to the feeds of all their followers. At small scale this is trivial; at Twitter/Instagram scale, a single post from a celebrity with 50 million followers must fan out to 50 million feed entries — a massive write amplification problem.

**Fanout-on-write (push model)**: When a user publishes a post, a background job immediately writes the post ID into each follower's feed cache (usually a Redis sorted set keyed by timestamp). Feed reads are O(1) — just fetch the pre-built list. The cost is write amplification: one post triggers millions of cache writes. For most users with <10K followers this is fine. For celebrities, a single tweet could overwhelm your write path.

**Fanout-on-read (pull model)**: The feed is computed lazily when the user opens their app. The system fetches the list of accounts the user follows, retrieves recent posts from each, merges and sorts them. No write amplification, but read latency is high and proportional to following count. Not viable for users who follow thousands of accounts.

**Hybrid approach** (what Twitter and Instagram actually use): Apply push to normal users (following count < threshold, e.g. 1M followers). Apply pull to celebrity accounts. When building a feed, merge the pre-built push cache with a real-time pull from celebrity accounts. The threshold is tunable — when a celebrity posts, you skip the fanout and let readers pull at read time.

Storage: each user's feed is typically a Redis sorted set of post IDs with the score as a timestamp. Only IDs are stored, not full post content — a separate lookup fetches post data. Feed length is capped (e.g., 800 entries) and older entries are evicted.

**Backfill and consistency**: new followers don't automatically get historical posts unless you backfill. Unfollows must purge entries — or tolerate stale entries with a grace window. These edge cases are often handled asynchronously.

At the infrastructure level, fanout jobs run as async workers (Celery, Kafka consumers, Sidekiq). Slow workers cause delivery lag — a post may appear in some feeds seconds before others, which is acceptable eventual consistency for social feeds.

Key Differences

AspectFanout-on-Write (Push)Fanout-on-Read (Pull)
Write costHigh — one write per followerLow — no writes on publish
Read latencyO(1) — pre-built cacheO(following_count) — computed on demand
StorageHigh — copies of post ID per followerLow — store once, compute per read
Stale data riskLow — feed updated at publish timeHigher — depends on cache TTL or freshness policy
Celebrity problemCatastrophic write amplificationHandles naturally — one post, many readers pull
Implementation complexityHigher — async fanout workers neededLower to start, harder to scale at read time
Used byTwitter (non-celebrities), InstagramTwitter (celebrities via hybrid), RSS readers

What Separates a 2/3 from a 3/3

2/3 — Passing but Incomplete

Correctly defines both push and pull models with their core trade-offs (write amplification vs. read latency) and mentions the celebrity/high-follower-count edge case.

3/3 — Strong Answer

Covers the hybrid model with a concrete threshold-based approach, explains the Redis sorted set data structure for feed storage, addresses backfill and unfollow edge cases, and mentions async fanout workers.

Common Mistakes

  • Presenting push and pull as mutually exclusive rather than combinable in a hybrid.
  • Not quantifying write amplification — a celebrity with 50M followers triggers 50M cache writes per post.
  • Forgetting to mention that only post IDs are stored in feed caches, not full post content.
  • Ignoring the unfollow and new-follower edge cases which are common interview follow-ups.

Follow-Up Questions

  • How would you handle a user with 100 million followers posting — what breaks in pure fanout-on-write? — 100M cache writes per post, latency spikes, potential Redis memory exhaustion — the hybrid model addresses this.
  • What data structure would you use for a user's feed in Redis and why? — Sorted set with timestamp as score allows efficient range queries for pagination; ZREVRANGE for newest-first.
  • How do you handle backfilling a feed when a user follows a new account? — Async job fetching the new account's recent N posts and inserting them into the follower's feed sorted set.
  • What consistency guarantees does your fanout design provide? — Eventual consistency — different followers see the post at different times; discuss whether this is acceptable for social feeds.

Related Questions

  • Consistent Hashing
  • Rate Limiting
  • CDN
  • Load Balancer — L4 vs L7
  • Distributed Transactions — 2PC, Saga

Can You Explain This Cold?

Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.

Get Graded — Free Assessment
GrindQuestionsAITechnical interview assessment
TermsPrivacyAbout