Skip to main content
  1. References/
  2. Architecture Design Basics/
  3. Pattern Taxonomy/
  4. Domain-Specific Patterns/

Real-time & Fan-out Patterns

·· 200 words· 1 min

🟠 P1 — how to push updates to many recipients; classic interview problem

Problem #

A user posts a message. Their 10,000 followers need to see it. Do you push it to all followers’ feeds immediately, or let followers pull it when they open the app?

Fan-out Strategies #

StrategyMechanismProsCons
Fan-out on writeOn post, write to every follower’s feedRead is fast (pre-computed)Write amplification (10K writes per post)
Fan-out on readOn read, query poster’s timelineWrite is fast (one write)Read is slow (assemble from many sources)
HybridFan-out on write for normal users, fan-out on read for celebritiesBalancedMore complex

Presence & Ephemeral State #

  • Heartbeat-based: Client sends periodic heartbeats; server marks offline after misses
  • Redis with TTL: SETEX user:123:online 30 true, refreshed by heartbeats

Instinct: Presence is best-effort. Don’t store in primary database. Redis with TTL keys is the standard.

Instinct #

Hybrid is the standard answer for social-media-style problems. Fan-out on write for users with <10K followers (pre-compute their feeds). Fan-out on read for celebrities (too many followers to write to). This is what Twitter famously does. The threshold is tunable based on write capacity.

References #