Publish/Subscribe (Pub/Sub)
MessagingAlso known as: publish-subscribe, fan-out messaging
Pub/Sub is a messaging pattern where publishers send messages to topics without knowledge of subscribers, and subscribers receive messages from topics they are interested in, enabling loosely coupled communication.
In the Pub/Sub pattern, publishers and subscribers are completely decoupled. Publishers emit events to named topics, and any number of subscribers can listen to those topics. This differs from a point-to-point message queue where each message is consumed by exactly one consumer.
Pub/Sub excels when a single event needs to trigger multiple independent actions. For example, when a user signs up, you might want to send a welcome email, create an analytics event, and provision their account — each handled by a separate subscriber.
Key considerations include fan-out (how efficiently the system delivers messages to many subscribers), message ordering, filtering (allowing subscribers to receive only a subset of messages), and backpressure handling.
Popular Pub/Sub implementations include Apache Kafka, Google Cloud Pub/Sub, Amazon SNS, and Redis Pub/Sub.
Related Terms
Ready to design?
Practice using publish/subscribe (pub/sub) in a real system design on Supaboard's interactive whiteboard.
Browse Challenges