What is Publish-Subscribe (Pub/Sub)?

Turkish: Yayınla-Abone Ol (Pub/Sub)

Publish-subscribe is a messaging pattern where publishers send events to topics and subscribers receive matching messages.

What is Publish-Subscribe (Pub/Sub)?

In Pub/Sub, the system that creates a message does not send it to each receiver directly. It publishes the event to a topic, channel, or subject. Services that subscribe to that topic receive the messages they care about. One event can therefore feed invoicing, notification, reporting, and search indexing at the same time.

How It Works

When an e-commerce system publishes an order.created event, the inventory service may reserve stock, the notification service may message the customer, and the data warehouse pipeline may store the order for analytics. The publisher only needs to know the event schema and topic; subscribers can be added later without changing the publisher.

Important design concerns include ordering, at-least-once delivery, consumer groups, replay, and schema versioning. Critical subscribers should be idempotent because a message may be delivered again after a retry.

Where It Is Used

Real-time notifications, microservice events, IoT streams, product catalog synchronization, and analytics pipelines all fit the Pub/Sub model. A message broker provides the infrastructure, while event-driven architecture makes events the main communication style of the system. Kafka is a common option when teams need high-volume event streams that can be retained and replayed.