Pub/Sub Architecture (original) (raw)

Last Updated : 17 Apr, 2026

Consider a scenario of synchronous message passing. You have two components sender and receiver in your system that communicate with each other.

The Pub/Sub model is a messaging pattern where a message broker routes messages from publishers to subscribers based on subscriptions, ensuring scalable and reliable delivery.

**Example: In a news notification system, when a publisher posts a new article, all users subscribed to that news topic automatically receive the update.

message_queue_

**Components

In the Pub/Sub (Publish/Subscribe) model, there are several key components that work together to enable communication between publishers and subscribers. These components include:

publisher_1

Working

Explain how the Pub/Sub architecture works:

Real-World Example

While this resembles Pub/Sub, real systems like Twitter use a hybrid approach involving caching, fan-out strategies, and ranking systems rather than a pure Pub/Sub model.

In this example, the Pub/Sub architecture allows for scalable and efficient distribution of tweets to followers. Publishers (users) can publish tweets without knowing who will receive them, and subscribers (followers) receive updates in real-time without the need for direct communication with the publishers.

Use-cases

The Pub/Sub (Publisher/Subscriber) architecture is widely used in various scenarios where asynchronous and scalable communication between components is required. Some common use cases of Pub/Sub architecture include:

Types of Pub/Sub Services

The examples of Pub/Sub services provided by specific cloud platforms (e.g., Google Cloud) are:

1. Pub/Sub Service

This is the main messaging service that most users and applications choose. It provides:

2. Pub/Sub Lite Service

This is a separate messaging service designed to be more cost-effective but comes with some trade-offs:

Comparing Pub/Sub to other Messaging Technologies

The comparison of Pub/Sub to other messaging Technologies is:

When to Use

Use Pub/Sub Architecture when:

When Not to Use

Do not use Pub/Sub Architecture when:

Benefits

The benefits of Pub/Sub Architecture are:

Challenges

The challenges of Pub/Sub Architecture are:

Pub/Sub Vs Point to Point Messaging

The differences between Pub/Sub and Point to Point Messaging are:

Pub/Sub Messaging Point-to-Point Messaging
Messages are broadcast to multiple subscribers. Messages are delivered to a single receiver.
Publishers do not need to know about subscribers. Sender must know the receiver.
Highly scalable because new subscribers can be added easily. Less scalable since messages are sent directly to a specific receiver.
Loosely coupled architecture. Tightly coupled communication.
Used for broadcasting events to many services. Used for direct one-to-one communication.
Examples: Google Cloud Pub/Sub, Amazon SNS, Kafka. Examples: JMS queues, AMQP queues, RabbitMQ queues.