Tuesday, October 12, 2021

Kafka v/s RabbitMQ - Let's compare both

Hello Friends,

I have published posts about "Apache Kafka" in my previous posts, Check it first if you want to learn it's basic concepts.

What is Apache Kafka? 

> Apache Kafka, Setup it


So, now let's compare Apache Kafka with RabbitMQ.


What is it?

Kafka - Apache Kafka is an event streaming platform. In simple words, for high-ingress data streams and replay, Apache Kafka is a message bus optimised.
RabbitMQ - RabbitMQ is the most widely deployed open source message broker. It’s Solid, mature, general-purpose message broker which supports various standardised protocols like AMQP, STOMP, MQTT, HTTP and WebSockets


Asynchronous Messaging Patterns

Kafka
- Apache Kafka isn’t an implementation of a message broker. Instead, it’s a distributed streaming platform. Kafka’s storage layer is implemented using a partitioned transaction log. Kafka also provides a Streams API to process streams in real time and a Connectors API for easy integration with various data sources
RabbitMQ - Based on queues and exchanges, RabbitMQ is an implementation of a message broker — often referred to as a service bus. It natively supports both messaging patterns ephemeral & durable.


Primary Use

Kafka - Build applications that process and re-process streamed data on disk.
RabbitMQ - It process high-throughput and reliable background jobs, communication and integration within, and between applications.


Support for High Availability

Kafka - Yes, Apache Kafka supports high availability.
RabbitMQ - It also supports high availability.


Federated Queues

Kafka - No, Kafka does not support federated queues.
RabbitMQ - Supports federated queues. This feature offers a way of balancing the load of a single queue across nodes or clusters.


Management & Monitoring

Kafka - Yes, HTTP-API, command line tool & Kafka Tool (GUI)
RabbitMQ - Yes, HTTP-API, command line tool, and UI (dashboard) for managing and monitoring RabbitMQ.


Retry logic and dead-letter

Kafka - No
RabbitMQ - Yes, It supports dead letter queue


Message Time-To-Live (TTL)

Kafka - No
RabbitMQ - Yes


Delayed/scheduled messages

Kafka
- No,
RabbitMQ - Yes


Message retention

Kafka
- Kafka persists all messages by design up to a configured timeout per topic. In regards to message retention, Kafka does not care regarding the consumption status of its consumers as it acts as a message log.
Consumers can consume every message as much as they want, and they can travel back and forth “in time” by manipulating their partition offset. Periodically, Kafka reviews the age of messages in topics and evicts those messages that are old enough.
RabbitMQ - RabbitMQ removes messages from storage as soon as consumers successfully consume them. This behavior cannot be modified. It is part of almost all message brokers’ design.


Fault handling

Kafka - Kafka does not provide any dead-letter mechanisms out of the box. With Kafka, it is up to us to provide and implement message retry mechanisms at the application level.
RabbitMQ - Provides tools such as delivery retries and dead-letter exchanges (DLX) to handle message processing failures due to Transient or Persistent(bug in consumer script) issues.


Scale

Kafka - Yes, Its architecture using partitions means it scales better horizontally (scale-out).
RabbitMQ - Yes, It scales better vertically (scale-up).


Hosted Solution & Enterprise Support

Kafka - Yes, CloudKarafka
RabbitMQ - Yes, CloudAMQP


When to Use Which?
Kafka is preferable when we require:
1. Strict message ordering.
2. Message retention for extended periods, including the possibility of replaying past messages.
3. The ability to reach a high scale when traditional solutions do not suffice.


RabbitMQ is preferable when we need:
1. Advanced and flexible routing rules.
2. Message timing control (controlling either message expiry or message delay).
3. Advanced fault handling capabilities, in cases when consumers are more likely to fail to process messages (either temporarily or permanently).
4. Simpler consumer implementations.



Bottomline:
While RabbitMQ and Kafka are sometimes interchangeable, their implementations are very different from each other. As a result, we can’t view them as members of the same category of tools; one is a message broker, and the other is a distributed streaming platform.
So in an event-driven architecture-based system, we could use RabbitMQ to send commands between services and use Kafka to implement business event notifications.

I hope this post will help you to choose Kafka or RabbitMQ for your backend architecture.


Thank You

No comments:

Post a Comment