Tutorials System Design Mastery
Pub/Sub vs Point-to-Point communication
On this page
Messaging Patterns
Should one message go to one person, or to everyone? Choosing the right messaging pattern determines how easily you can add new features in the future.
1. Point-to-Point (Queue)
One producer sends a message to exactly one consumer. If multiple consumers exist, they "Competing Consumer" pattern is used—only one gets each message. Best for: Processing payments or sending a single email.
2. Publish/Subscribe (Topic)
The producer publishes to a "Topic." Multiple "Subscribers" can listen to that topic. Every subscriber gets a copy of the message. Best for: Notification systems, Updating multiple caches, or logging.
4. Interview Mastery
Q: "How does Pub/Sub enable 'Plug-and-Play' microservices?"
Architect Answer: "Because the Producer doesn't know who is listening. If you have an 'OrderPlaced' event, today only the 'Shipping' service listens. Tomorrow, if you want to add a 'Marketing' service that sends a coupon, you just point it to the topic. You don't have to change a single line of code in the 'Order' service. This is the ultimate in architectural decoupling."
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!