MESSAGE BROKERS – WHAT ARE THEY, WHAT ARE THEY COMPOSED OF, AND PROS AND CONS: COMPARING APACHE KAFKA, REDIS AND RABBITMQ
When working on a project, developers, analysts, and testers have to participate in the architecture design process. To understand how different parts of the system or services can interact with each other, you need to understand message brokers since they are often used to build communication between system components.
In this article we will understand what message brokers are, what they consist of and when they are used together with their pros and cons. We will also look at the features of the three most popular brokers – Apache Kafka, RabbitMQ and Redis.
A message broker is an architectural pattern used in distributed systems. It is a software component that serves as an intermediary in communication between different parts of the system. It is implemented as part of the overall system architecture, or as a separate service.
WHAT DOES A MESSAGE BROKER?CONSIST OF?
Any message broker uses two main entities:
The message is sent directly from the sender to the recipient.
There is also a Topic – a logical unit that unites all messages according to some criterion.
Publish/subscribe scheme.
?
There are two main algorithms for sending messages to a queue:
WHEN TO USE? BROKERS
There are many cases when brokers are used. Let's look at the main ones:
PROS AND CONS?OF USING BROKERS
Like any other technology, message brokers have their pros and cons:?
PROS
CONS
Fault tolerance and scalability. Helps create fault-tolerant and scalable systems thanks to asynchronous data processing and the ability to use broker clusters.
Complication of the system. The use of brokers will entail an increase in the complexity of the system by adding a new element to it. Debugging, maintenance and administration become more difficult.
Separation of layers. Allows the separation of application layers reducing the coupling between them, which makes it possible to make the application more modular, flexible and easy to develop. It will also be useful when organizing a microservice system.
Difficult to learn. Learning this software can take a long period of time due to the complexity of the architecture.
Message delivery guarantees. Provide guarantees for message delivery. If the recipient is not ready to process the received information at the moment, it will be stored in a queue, and the recipient can process it later.
Additional point of failure. This is the point of possible critical failure where most systems will not be able to function. However, many brokers provide high availability and reliable operation. This is a potential performance bottleneck. Therefore, modern brokers are designed to be highly scalable.
Productivity increase. Using brokers can improve performance by processing messages asynchronously.
Additional load on the network. The use of brokers may result in additional network load due to data transfer.
Safety. Provide encryption and authentication mechanisms to ensure secure data exchange.
Possibility of version conflicts: If system participants use different versions of protocols or different implementations of message brokers, compatibility problems may arise. This may result in incorrect processing or loss of messages.
POPULAR MESSAGE BROKERS
In fact, there are a huge number of message brokers on the market now. For example, Apache Kafka, RabbitMQ, Redis, Apache ActiveMQ, Amazon SQS, Apollo, Google Pub/Sub and others. This list can go on for a long time, but we will focus on the first three since they are most often used in modern development.
We compared brokers based on a number of criteria. For comparison, we’ll highlight three main criteria that will influence the choice:
?Broker
Scale
Data Persistency
Client capabilities
Apache Kafka
Very fast, allows you to process more than 1 million messages per second
Yes
One-to-many
RabbitMQ
About 50 thousand messages per second (depending on configuration)
Supports permanent and temporary messages
One-to-one and one-to-many
Redis
Up to 1 million messages per second
Partial implementation
One-to-one and one-to-many
Features of Apache Kafka
One of the most popular brokers which is quite actively used and has a lot of features?
Features of Rabbit MQ
It is also one of the popular brokers. It is less productive compared to Kafka, but it has its advantages.?
There are difficulties when scaling horizontally in a cluster.
Features of Redis
IN WHAT CASES SHOULD EACH BROKER BE USED?
The choice of a message broker depends on the specific requirements and context of use.
Apache Kafka
RabbitMQ
Redis
when you need to process a large amount of data that is generated very quickly
no big data flow
processing of large volumes of data is required
when implementing transactional or pipeline systems
flexibility of message routing within the system is important
no persistence required
when building an event-driven architecture
the fact of message delivery is important
high speed of message delivery is required
when using a buffer for logs and metrics
?
?
CONCLUSION
Brokers are now very actively used in the construction of large information systems. You shouldn’t make a definite conclusion about which broker is better; we recommend working with several and choosing yourself because it all depends on the context in which it will be used. The choice of a specific solution must be made based on the task that is assigned to you at the current moment of work.?