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β