← Back to list

Messaging Models in System Design: Point-to-Point vs. Publish-Subscribe

Messaging in distributed systems enables asynchronous communication via message queues (one-to-one) or pub-sub (one-to-many) communication.

Software Engineer Notes · 2025-03-18 15:22 · 11 claps · 2.7 min read
#system-design-interview #system-design-concepts #message-queue #publish-subscribe-pattern #messaging
Open on Medium ↗

Messaging Models in System Design: Point-to-Point vs. Publish-Subscribe

In distributed systems, communication between components is crucial for ensuring smooth operations. One common approach is messaging, an asynchronous and indirect method of exchanging data. Unlike direct communication, messaging allows senders and receivers to operate independently, improving system resilience and scalability.

A key component in messaging systems is the message broker, software that facilitates message exchange between distributed components. It helps decouple systems, providing buffering, routing, and reliability guarantees.

What is a Message?

A message is a piece of data sent from one component to another. It can contain any type of information, such as requests, responses, event notifications, or log data.

Messaging Characteristics

  • Asynchronous: The sender and receiver do not have to interact at the same time.
  • Indirect Communication: Components do not communicate directly; instead, they exchange messages via a message broker.
  • Reliability and Decoupling: Messaging systems help in handling failures and scaling components independently.

Messaging Models

There are two primary messaging models: Point-to-Point (Queue-based Messaging) and Publish-Subscribe (Topic-based Messaging).

1. Point-to-Point (Message Queues)

In the point-to-point model, messages are sent to a queue, where they are processed by a single consumer.

Message queue with two consumers — each message is processed by a single consumer

Message queue with two consumers — each message is processed by a single consumer

How It Works:

  1. A sender (producer) sends a message to a message queue.
  2. A receiver (consumer) retrieves and processes the message.
  3. The message is removed from the queue after being successfully processed.

Key Characteristics:

  • One-to-One Communication: Each message is processed by only one consumer.
  • Durability: Messages can be stored in memory or persisted to disk.
  • Decoupling: Components can be developed, deployed, and scaled independently.
  • Scalability: Consumers can scale horizontally to handle high message loads.
  • Reliability: Messages remain in the queue until they are acknowledged by the consumer.

Delivery Mechanisms:

  • Push Delivery: The consumer is notified immediately when a new message is available.
  • Pull Delivery: The consumer periodically polls the queue for new messages.

Use Cases:

  • Task processing (e.g., job queues in background workers)
  • Order processing systems
  • Email or notification systems

2. Publish-Subscribe (Pub-Sub)

In the publish-subscribe model, messages are sent to a topic and received by multiple subscribers.

Publish-Subscribe model with two consumers — each of them consumes the whole set of messages

Publish-Subscribe model with two consumers — each of them consumes the whole set of messages

How It Works:

  1. A sender (publisher) sends a message to a topic.
  2. Multiple receivers (subscribers) listen to the topic and receive the message.
  3. The message remains available in the topic for new subscribers.

Key Characteristics:

  • One-to-Many Communication: Multiple subscribers receive the same message.
  • Broadcasting: Messages are sent to all subscribers.
  • Decoupling: Publishers and subscribers do not need to be aware of each other.
  • Scalability: Many subscribers can process the same message in parallel.
  • No Acknowledgment Required: Subscribers do not need to acknowledge message receipt.

Use Cases:

  • Event-driven architectures (e.g., real-time analytics, notifications)
  • IoT messaging
  • Logging and monitoring systems

Comparing Message Queues and Publish-Subscribe

Message Queues

  • Communication Type: One-to-One
  • Message Storage: Removed after consumption
  • Reliability: Requires acknowledgment
  • Use Case: Task distribution, job processing

Publish-Subscribe

  • Communication Type: One-to-Many
  • Message Storage: Retained in topic for subscribers
  • Reliability: No acknowledgment required
  • Use Case: Event broadcasting, notifications

Choosing the Right Model

Selecting the appropriate messaging model depends on system requirements:

  • Use message queues when you need reliable, ordered, and single-consumer message processing.
  • Use publish-subscribe when you need to broadcast messages to multiple consumers without strict delivery guarantees.

Conclusion

Messaging plays a vital role in distributed systems, enabling asynchronous and decoupled communication. Understanding the point-to-point and publish-subscribe models helps in designing scalable, reliable, and maintainable systems. Whether processing tasks sequentially or broadcasting events, choosing the right messaging model is key to efficient system design.

Further Reading


메타데이터
post_id
b6ef74cb6fee
slug
messaging-models-in-system-design-point-to-point-vs-publish-subscribe-b6ef74cb6fee
url
https://medium.com/@software.engineer.notes/messaging-models-in-system-design-point-to-point-vs-publish-subscribe-b6ef74cb6fee
canonical_url
https://medium.com/@software.engineer.notes/messaging-models-in-system-design-point-to-point-vs-publish-subscribe-b6ef74cb6fee
author_url
https://medium.com/@software.engineer.notes
status
ok
fetched_at
2026-07-31 21:25:58