/pʌb ˈsʌb/
noun — "asynchronous messaging model for decoupled communication."
Pub/Sub (short for Publish/Subscribe) is a messaging pattern in which senders (publishers) do not send messages directly to specific receivers (subscribers), but instead categorize messages into channels or topics. Subscribers express interest in one or more topics and receive only messages that match those topics. This decouples the sender and receiver, enabling scalable, asynchronous communication across distributed systems.
Technically, a Pub/Sub system consists of three core components: the publisher, the subscriber, and the message broker. Publishers push messages to the broker, which handles routing based on topic subscriptions. Subscribers register interest in topics, and the broker ensures delivery, either immediately or via persistent queues. This mechanism supports both transient and durable subscriptions depending on system requirements.
Common implementations include cloud messaging services like Google Cloud Pub/Sub, Kafka (when used in pub/sub mode), and MQTT brokers. Messages may carry structured payloads in formats such as JSON, Protocol Buffers, or Avro. Delivery semantics vary by system: at-most-once, at-least-once, or exactly-once guarantees, affecting reliability and idempotency considerations.
In workflow terms, a sensor network might publish telemetry data to a topic like temperature-readings. Multiple processing services subscribe to this topic: one logs the readings, another triggers alerts if thresholds are exceeded, and another aggregates metrics. None of these services need direct knowledge of each other, and the publisher does not need to know the number of subscribers.
Pub/Sub is often paired with streaming systems for real-time event handling. Publishers continuously generate events, brokers buffer and route them, and subscribers process events asynchronously. This allows scaling out consumers independently, supporting high-throughput, low-latency architectures common in microservices and IoT ecosystems.
Conceptually, Pub/Sub acts as a message switchboard: publishers deposit messages at labeled slots (topics), and subscribers pull from slots they care about. This abstraction simplifies complex, distributed communication patterns, promotes loose coupling, and allows systems to evolve independently without breaking contracts between producers and consumers.