Bird
Raised Fist0
HLDsystem_design~12 mins

Fan-out on write vs fan-out on read in HLD - Architecture Patterns Compared

Choose your learning style9 modes available
System Overview - Fan-out on write vs fan-out on read

This system demonstrates two common strategies for distributing updates to multiple users: fan-out on write and fan-out on read. The goal is to deliver timely updates to users' feeds while balancing system load and latency.

Fan-out on write pushes updates to all followers when a user posts, while fan-out on read fetches updates from all followed users when a user reads their feed.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-----------------------+
  |                       |
Fan-out on Write Service  Fan-out on Read Service
  |                       |
  v                       v
Write DB               Read DB
  |                       |
  v                       v
Cache                   Cache
  |                       |
  +-----------+-----------+
              |
              v
           User Feed
Components
User
client
End user who reads and writes posts
Load Balancer
load_balancer
Distributes incoming user requests evenly to API Gateway
API Gateway
api_gateway
Routes requests to appropriate fan-out services
Fan-out on Write Service
service
Pushes new posts to all followers' feeds immediately on write
Fan-out on Read Service
service
Fetches posts from all followed users when a feed is requested
Write DB
database
Stores posts and follower relationships for fan-out on write
Read DB
database
Stores posts and follower relationships for fan-out on read
Cache
cache
Speeds up feed retrieval by caching user feeds or posts
User Feed
output
Final feed data delivered to the user
Request Flow - 10 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayFan-out on Write Service
Fan-out on Write ServiceWrite DB
Fan-out on Write ServiceCache
API GatewayFan-out on Read Service
Fan-out on Read ServiceCache
Fan-out on Read ServiceRead DB
Fan-out on Read ServiceCache
Fan-out on Read ServiceUser Feed
Failure Scenario
Component Fails:Cache
Impact:Feed reads become slower due to cache misses; writes still succeed but no fast feed updates
Mitigation:System falls back to database queries; cache rebuilds gradually; consider cache replication and monitoring
Architecture Quiz - 3 Questions
Test your understanding
Which component immediately updates followers' feeds when a user posts?
AAPI Gateway
BFan-out on Read Service
CFan-out on Write Service
DLoad Balancer
Design Principle
This architecture contrasts two fan-out strategies: pushing updates on write reduces read latency but increases write load, while pushing on read reduces write load but increases read latency. Caches help improve performance in both cases by reducing database hits.