Skip to main content

What is the Publisher-Subscriber pattern?

Senior JavaScript
Quick Answer Pub-Sub extends Observer by adding a broker between publisher and subscriber รขโ‚ฌโ€ neither knows about the other directly. Publishers send messages to a channel; subscribers listen to channels. In JavaScript, this is implemented with an EventBus or EventEmitter where neither the publisher nor the subscriber holds a reference to each other. Even more decoupled than Observer.

Answer

Pub-Sub decouples senders (publishers) from receivers (subscribers) through a central event hub.

Useful for modular architectures, micro frontends, and Node.js event emitters.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice