Rwitesh Bera
Rwitesh Bera

Follow

Rwitesh Bera

Follow
The Importance of Message Brokers in Modern Distributed Systems

The Importance of Message Brokers in Modern Distributed Systems

How Message Brokers Enable Communication in Microservices Architecture

Rwitesh Bera's photo
Rwitesh Bera
·Apr 30, 2023·

4 min read

Play this article

Introduction

Modern applications are becoming increasingly intelligent and complex. To handle the increasing complexity and scalability challenges, developers split applications into a set of microservice instances. However, this approach can create challenges, as developers often encounter communication issues related to software components while processing data. because those components are often built using different programming languages. This is where the message broker comes in. A message broker is like a middleman that helps different services communicate with each other. In this article, we will explore the concept of a message broker in detail and learn how it is crucial to enabling communication within a distributed system.

What is the purpose of using a message broker?

Message broker is a software that acts as a middleware between different services. It is a standardized medium that handles the flow of data between the services and allows them to communicate internally within an application. It supports asynchronous messaging. Now you will ask what asynchronous communication is. Asynchronous messaging is a method where the sender and receiver don't need to rely on each other to exchange messages. Both participants are free to start, pause, or resume producing or consuming messages without waiting for others. This improves fault tolerance and resiliency in the system and makes it easier to scale the software. Message brokers ensure that messages are properly delivered between different components. if a component is not available at the time a message is sent. The message is stored in a queue and delivered when the component becomes available again. This ensures that no messages are lost, even if components are temporarily unavailable due to connectivity or any other issue.

Protocols used in Message Broker

Message brokers use different protocols for communication. Here are some popular protocols commonly used by message brokers:

  1. AMQP (Advanced Message Queueing Protocol)

  2. MQTT (Message Queueing Transport)

  3. SMQP (Simple Message Queue Protocol)

  4. STOMP (Simple Text-Oriented Messaging Protocol)

  5. REST (Representational State Transfer)

Different message brokers may support different protocols, so it's important to choose a message broker that supports the protocols required by your application.

Messaging Patterns

Message brokers generally use two messaging patterns:

  • Point-to-point messaging

    In this messaging approach, there is a direct relationship between the sender and receiver. The sender creates a message and directly delivers it to a specific destination, which is typically the address of the receiver. For example, it can be used in financial systems for transferring funds between accounts.

  • Publish/Subscribe or pub/sub messaging:

    This messaging pattern is like the broadcasting approach, where the producer publishes messages for a specific station or topic, and multiple consumers connected to or subscribed to the station can consume them. For example, a news agency publishes new articles about cricket. These articles are sent to 'sports' topic. and subscribers who have subscribed to the topic can receive the articles and display them in their components.

Use cases

Here are some real-life use cases for message brokers:

  1. In an e-commerce system, a message broker can be used to process the orders.

  2. In financial services, a message broker can be used to process transactions.

  3. used to handle notifications and messages on social media.

  4. In a streaming service, a message broker can be used to handle video encoding and delivery.

Examples of Message Brokers

  1. Memphis: the next-generation open-source message broker. A simple, robust, durable, cloud-native project written in Go

  2. RabbitMQ: Released in 2007. lightweight, easy-to-deploy message brokers written in Erlang.

  3. Apache Kafka: free and distributed event streaming platform that operates on a pull-based model. This means that the consumer of the messages must actively request messages from a particular offset.

  4. Apache ActiveMQ: open-source message broker based on the Java Message Service (JMS) specification, which provides a standard API for sending and receiving messages between services.

Conclusion:

A message broker can be valuable software for developing distributed systems, but it may not always be the best solution. Simple applications with few services, tightly coupled services, limited developers, and low latency requirements are some scenarios where we shouldn't use a message broker. Ultimately, the decision should be based on the requirements, complexity, and scalability of the application.

 
Share this