Course contentsShow
← System Design
Lesson 662 of 1,91918. Message Queues and BrokersFree lesson

Fan-Out with Pub-Sub

Broadcasting single events to multiple independent services using pub-sub's natural fan-out capability.

Fan-Out with Pub-Sub

What You'll Learn

You'll learn how a single published message can be automatically delivered to multiple independent subscribers, enabling one-to-many communication patterns in distributed systems.

The Core Concept

Fan-out is when a single event triggers multiple parallel actions. In pub-sub systems, this happens naturally: when a publisher sends one message to a topic, every subscriber to that topic receives their own copy of that message.

Think of it like a TV broadcast: when a news channel transmits a breaking story, every television tuned to that channel receives the same content simultaneously. The broadcaster doesn't need to know who's watching or send individual copies—the infrastructure handles the distribution automatically.

How Fan-Out Works in Pub-Sub

  1. A publisher sends one message to a topic (e.g., "OrderPlaced")
  2. The message broker identifies all active subscribers to that topic
  3. The broker delivers independent copies to each subscriber
  4. Each service processes the message according to its own logic

Real-World Example

When a user completes a purchase:

  • Publisher: Order Service publishes "OrderCreated" event
  • Subscriber 1: Email Service sends confirmation
  • Subscriber 2: Inventory Service updates stock
  • Subscriber 3: Analytics Service records metrics
  • Subscriber 4: Loyalty Service awards points

All four services receive and process the same event independently, in parallel. No service knows about the others—they're completely decoupled.

Why It Matters

Fan-out enables event-driven architectures where adding a new feature often means adding a new subscriber, not modifying existing services. When you need to trigger analytics tracking later, you subscribe without changing the order flow.

Key Takeaway: Pub-sub's natural fan-out capability allows one published message to broadcast to multiple independent services automatically, enabling parallel processing and loose coupling without point-to-point integrations.