Pub/Sub Messaging Model

Pub/Sub Messaging Model

Pub-Sub messaging is an asynchronous communication method used in microservices architecture. The Pub-Sub model consists of three components.

  • A publisher who publishes message.
  • A message broker or topic where the messages are pushed.
  • A subscriber who receives the message via a message broker.

Pub/Sub messaging allowing to create decoupled applications easily with a reliable communication method and enables users to create Event-driven architectures. Event-driven architecture (EDA) is a software design pattern that enables a system to detect events (such as a transaction or site visit) and act on them in real time or near real time. This pattern replaces the traditional Request/Response architecture where services would have to wait for a reply before they could move onto the next task.

There are two types of message distribution patterns namely Point-to-point messaging and Publish-Subscribe.

In Point-to-point messaging, there is one-to-one relation between the sender and the receiver of the message. Each message is sent and consumed only once. This pattern is used when some action needs to be performed only once. Traditional message queues use this pattern.

In publish-subscribe, the sender of the message doesn’t know anything about receivers. The message is being sent to the topic. After that, it’s distributed among all endpoints subscribed to that topic. It can be useful e.g. for implementing notifications mechanism or distributing independent tasks.

A pub/sub model allows messages to be broadcasted asynchronously across multiple sections of the applications.

The main component that facilitates this functionality is something called a Topic. The publisher pushes messages to a Topic, and the Topic instantly pushes the message to all the subscribers. This is what differentiates the Pub/Sub model from traditional message brokers, where a message queue batches individual messages until a user or service requests these messages and retrieves them.

Whatever the message is in the Pub/Sub model, it will be automatically pushed to all the subscribers. If there are user-created policies for certain subscribers then those will be filtered out.

This approach makes it possible to create event-driven services without constantly querying a message queue for messages. 

Pratima Upadhyay , message buses too have high performance and provide scalable messaging solutions. What factors do you take in consideration while deciding between the two options.

Pub-Sub model is a system which simplifies async programming processes and provides a simpler and scalable solution for eventual consistent systems to scale with less resource availability. Will be great if we can get a post on system describing combination messaging queues with pub sub model, stateful and stateless load-balancers processing high throughput data in resource constraint environment and providing acceptable throughput.

To view or add a comment, sign in

More articles by Pratima Upadhyay

  • The Rise of Indian SaaS Startups : Comparing SaaS with IaaS and PaaS

    Did you know, despite the tight macroeconomic pressure and funding crunch, Indian SaaS startups have raised more than…

    2 Comments
  • Master the Art of System Design: Enroll in My Live Course and Strengthen Your Fundamentals

    Register for the course Are you ready to take your technical skills to the next level? Look no further than my live…

    1 Comment
  • Properties of Pub Sub Architecture

    Topics in a publish-subscribe system not only act as intermediaries between publishers and subscribers, but they also…

    5 Comments
  • What are coroutines and how are they different from threads?

    Coroutines are a programming construct that can be thought of as a lightweight version of threads. While threads are…

    2 Comments
  • How are user passwords managed and validated in databases?

    Did you know, back in 2005, Reddit developers confirmed that a hacker had stolen backup copies of their database that…

    3 Comments
  • Pub/Sub Messaging Model

    Pub-Sub messaging is an asynchronous communication method used in microservice architecture. The Pub-Sub model consists…

    4 Comments
  • An introduction to Kubernetes

    What is Kubernetes and why is it so popular? Kubernetes is an open source container orchestration tool developed by…

    2 Comments
  • An introduction to Containers

    Have you ever wondered what is the buzz around containers and why is everyone moving towards containerizing their…

    2 Comments
  • The birth and rise of NoSQL

    The acronym NoSQL was first used in 1998 by Carlo Strozzi while naming his lightweight, open-source “relational”…

    3 Comments
  • Replication and Sharding

    Replication refers to having several copies of the same dataset hosted on separate machines in order to maintain…

    12 Comments

Others also viewed

Explore content categories