navigation

Message queue vs message broker – what’s the difference?

Message queue vs message broker – what’s the difference?

by
May 10, 2022

Microservice architectures have been the preferred choice for designing software solutions for quite some time. In general, the idea is to have a system, consisting of multiple small applications performing different tasks. So, here comes the question – how are these different applications communicating in order to form a whole and complete software product? In this article, we will explain the difference between message queue vs message broker, their use cases, and whether or not we can use them together as a means of communication between software applications.

What is a message queue?

A queue is a data structure where the piece of information, which entered the queue first is also transmitted first. This programming concept is also known as FIFO, or First-In-First-Out.

Imagine you have a pipe and you are holding one end of the pipe. Your friend is holding the other end. You start adding little stones to the pipe. The first stone you added will be the first stone, which arrives at the other end of the pipe and into your friend’s hands. A pretty simple concept, isn’t it? A message queue works in the exact same way, only with messages and not stones.

Messages are the bits of information, which we want to transmit. Services can have message queues, which contain an array of sequentially sorted calls, sent to the desired destinations. The information in the queue is stored until it is received by the correct service. Producers are the applications, which create messages and push them to the queue. On the other side, the applications, which look through the queue and receive those messages are called consumers. The usage of the message queue also enables asynchronous communication between the different services. When sending the information, the producer can keep working without interruption, allowing the consumer application to process the information at its own pace. 

message queue, message broker, communication styles in applications, software engineering, Dreamix, message brokers, message queues, microservices, microservice architecture
Photo: Shutterstock

What is a message broker?

To answer the question, a message broker is simply software, which provides means for stable and reliable communication between different applications. But what if those applications and services are in different languages and don’t use the same technology stack? Not to worry as translating the information between messaging protocols is a part of the message broker’s work. What else is the message broker responsible for? Well, message brokers store, route, and deliver information to the desired destination. In general, their purpose is to allow applications to communicate internally thus playing the part of a communications layer. Senders can issue messages even without knowing who the receivers of those messages are, how many of them there are, and even if those receivers are active at the moment or not.

message queue, message broker, communication styles in applications, software engineering, Dreamix, message brokers, message queues, microservices, microservice architecture
Photo: Shutterstock

Different messaging styles

Now that we know what a message broker is, let’s look at the different messaging styles, more specifically point-to-point messaging and publish-subscribe messaging.

  • Point-to-point messaging uses message queues in such a way that the messages’ sender and receiver have a one-to-one relationship. This type of messaging style is used when a guarantee is needed that each message will be sent and consumed only once. For example, this is the preferred style to use when working with financial transactions.
  • The publish-subscribe messaging style enables the producer of the message to send it to a topic. The consumers subscribe to these topics and receive the information sent by the producers. So to say, the relationship between the sender and the receiver is one-to-many. When a message is published to a topic, it reaches all applications, who are subscribed to this topic. So, when is it appropriate to use this messaging style? For example, if a truck driver was to give updates about the situation on the road, more specifically the delay between different borders, people waiting to handle the cargo of the truck will be made aware of this delay and can go on with their work while waiting. Moreover, if those updates were made in a system designed for communication between drivers, other truck drivers would know and plan their trip according to the newly arised circumstances.

Message queue vs message broker: The differences

Message queues are responsible for the communication between applications by sending, receiving, and storing messages using the queue data structure. Even though we use message queues for data transfer, they are not aware of the contents of the information they are carrying. In essence, a message broker is simply a mechanism that extends the usage of message queues. Unlike the message queues, message brokers are aware of the contents of the information, carried through them. Also, message brokers can process information from all sorts of sources. For example, information read from files or HTTP requests.

In short, the message broker is responsible for:
  • The conversion between data transport protocols
  • The transformation of message formats between services
  • The routing of the communication between services
  • The distribution of events from various sources

As it turns out, message brokers use message queues to transmit information between all interested parties. Simply put, the message queue is a structure that stores the produced data until its consumption, and the message broker is a software component that manages the message queues.

Conclusion

In a microservice architecture, every microservice offers different functionality than the rest. However, they cannot perform those functionalities without keeping in touch with the other services. Message queues provide means for the different applications to push information to the queue. The message broker simply takes the information from the sender, translates it between different messaging protocols, if needed, and delivers the message to the correct receiver. 

So go on, and use a message broker in your next project! If any questions or issues arise, please feel free to contact us at Dreamix, and we will be more than happy to help you out!

Teodora Yovcheva

Junior Software Engineer at Dreamix

More Posts

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!