QA
Beginner LevelSystem Design & Architecture

What is the Publisher-Subscriber (Pub/Sub) pattern?

❓ Interview Prompt: Explain Publisher-Subscriber (Pub/Sub) messaging pattern, message topics, fan-out pattern, and decoupling event producers from subscribers.

The Publisher-Subscriber (Pub/Sub) pattern is an asynchronous messaging pattern where message senders (Publishers) do not send messages directly to specific receivers:

How Pub/Sub Works:

1
Publishers publish messages to named Topics on a Message Broker (Apache Kafka, RabbitMQ, Google Cloud Pub/Sub).
2
Multiple subscriber services subscribe to topics of interest.
3
Fan-Out: When a message is published, the broker automatically broadcasts a copy to ALL subscribed services concurrently!

Code Implementation Example

markdown
Pub/Sub Fan-Out Messaging Flow:

                      β”Œβ”€β”€> [Email Service Subscriber]
                      β”‚
[Publisher (Order Service)] ──> (Topic: 'order_created') ──┼──> [Inventory Service Subscriber]
                      β”‚
                      └──> [Analytics Service Subscriber]
πŸ’‘Pub/Sub fan-out architecture broadcasting order events to multiple subscribers.
🎯 Interview Key Takeaway

Use Pub/Sub messaging to broadcast events to multiple downstream consumer services without coupling the producer.

#System Design#PubSub#Messaging#Kafka#Beginner
Back to all System Design & Architecture Questions→

More System Design & Architecture Interview Questions

Beginner LevelSystem Design & Architecture

Explain the CAP Theorem and PACELC Theorem with real-world database examples.

Beginner LevelSystem Design & Architecture

What is Vertical Scaling (Scale Up) vs Horizontal Scaling (Scale Out)?

Beginner LevelSystem Design & Architecture

How do Load Balancers distribute traffic (Round Robin, Least Connections, IP Hash)?