Bird
Raised Fist0
HLDsystem_design~3 mins

Fan-out on write vs fan-out on read in HLD - When to Use Which

Choose your learning style9 modes available
The Big Idea

What if your favorite app could instantly show new posts without crashing or delays?

The Scenario

Imagine you run a social media app where millions of users post updates. When a user posts, you must send that update to all their followers. Doing this manually means sending messages to each follower one by one every time someone posts.

The Problem

This manual way is slow and clogs the system because sending updates to thousands or millions of followers at post time takes too long. It also risks errors and delays, making users wait to see new posts.

The Solution

Fan-out on write and fan-out on read are smart ways to handle this. Fan-out on write sends updates to followers immediately when a post happens, so reading is fast. Fan-out on read keeps posts in one place and sends them to followers only when they check, saving work upfront but making reads slower.

Before vs After
Before
for follower in followers:
    send_update(post, follower)
After
Fan-out on write: store post in each follower's feed at write time
Fan-out on read: store post once, fetch for followers when they read
What It Enables

These approaches let apps handle millions of users smoothly by balancing speed and resource use for posting and reading updates.

Real Life Example

Twitter uses fan-out on write to quickly show tweets to followers, while Instagram uses fan-out on read to save storage and compute when showing posts.

Key Takeaways

Manual sending to followers is slow and error-prone.

Fan-out on write pushes updates early for fast reads.

Fan-out on read delays pushing updates to save resources.