0
0
Firebasecloud~3 mins

Why Fan-out writes pattern in Firebase? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your app could share updates instantly with everyone, without missing a beat?

The Scenario

Imagine you have a social app where a user posts a message, and you want that message to appear instantly on all their friends' feeds.

If you try to update each friend's feed one by one manually, it feels like sending a letter to each friend separately every time you post.

The Problem

Manually updating each friend's feed is slow and prone to mistakes.

If the app crashes halfway, some friends won't see the post.

It also wastes time and resources, making the app feel sluggish.

The Solution

The fan-out writes pattern solves this by automatically copying the post to all friends' feeds in one go.

This way, the app updates everyone efficiently and reliably, like sending a group message instead of many letters.

Before vs After
Before
for friend in friends:
  database.update(friend.feed, new_post)
After
database.update({friend1.feed: new_post, friend2.feed: new_post, /* ... */})
What It Enables

This pattern makes real-time updates fast and consistent across many users, improving user experience and app reliability.

Real Life Example

When you post a photo on a social network, fan-out writes ensure all your followers see it quickly in their feeds without delay or missing updates.

Key Takeaways

Manual updates to many places are slow and risky.

Fan-out writes copy data efficiently to multiple locations at once.

This improves speed, reliability, and user satisfaction.