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

Pub-Sub Use Cases: Event Broadcasting

Applying pub-sub for event notifications, cache invalidation, and decoupling microservices through events.

Pub-Sub Use Cases: Event Broadcasting

What you'll learn: How pub-sub messaging enables event-driven architectures through real-world scenarios like notifications, cache invalidation, and microservice decoupling.

The Core Idea

While point-to-point queues distribute work to one consumer, pub-sub shines when multiple independent systems need to react to the same event. Think of it like a news broadcast: when something happens, every interested party gets notified simultaneously without knowing about each other.

Real-World Applications

Event Notifications
When a user uploads a profile photo, multiple services care: the thumbnail generator, the moderation system, the notification service, and the activity feed. Each subscribes to the "ProfilePhotoUploaded" topic and processes the event independently. The photo service doesn't need to know who's listening—it just publishes once.

Cache Invalidation
When data changes in your database, all distributed cache nodes need to know. Instead of the database calling each cache individually (tight coupling), it publishes an "ItemUpdated" event. Every cache instance subscribed to that topic invalidates its local copy. Add a new cache server? Just subscribe it—no code changes needed.

Microservice Decoupling
In an e-commerce system, when an order is placed, the inventory service reduces stock, the shipping service creates a label, the email service sends confirmation, and the analytics service logs the sale. Rather than the order service calling each one directly (creating dependencies), it publishes an "OrderPlaced" event. Services subscribe and react independently. If shipping goes down, the order still completes.

Why This Matters

Pub-sub transforms rigid service dependencies into flexible event streams. Publishers don't know or care who's listening. Subscribers come and go without affecting publishers. This temporal and spatial decoupling makes systems more resilient and easier to evolve.

Key Takeaway: Pub-sub excels when multiple independent systems need to react to the same event—enabling event notifications, distributed cache coherence, and loosely-coupled microservices that can evolve independently.