- Asynchronous
- A producer doesn’t wait for the message to be processed.
- Decoupling
- Producers are completely unaware of consumers (Don't have to know the IPs and ports of receivers).
- Producers or consumers can be modified and deployed independently.
- Buffering/Rate limiting
- It can act as a buffer if the consumer is unavailable or overloaded.
- Fan-out
- The producer simply drops the message on the queue, and the multiple consumers process the message based on their needs at their own pace.
- Single point of failure
- The message queue can be a potential single point of failure.
- Increase complexity
- Increase system complexity and operational complexity.
-
Supported programming languages
-
Message ordering
- The order of messages can be preserved by the queue or not.
-
Message retention/expiration
- The limited period of time the message will be retained in the queue before being discarded.
-
Delivery guarantees
-
Availability
-
Scalability
-
Latency
RabbitMQ | Kafka | |
---|---|---|
Protocol | AMQP | Binary protocol over TCP |
Message routing | Support multiple routing rules | Single |
Message consumption | push | pull |
Message ordering | Ordered at queue level | Ordered at partition level (Not topic level) |
Message deleteion | Delete on ACK | Delete on retention period expires |
Message deleyed delivery | Support | Not support |
Message delivery gurantees | ||
Message persistence | Less | Strong (persisting messages to disk) |
Message pileup pressure | Cannot handle very well | |
Client API | ||
Federated queues | Yes | No |
Complexity | Less | More |
Throughput | 20K / sec | Millions / sec |
Scaling strategies | Mostly vertical scaling | Horizontal scaling |
Learning curve | Gentle | Steep |
Ecosystem | Smaller | Larger |
- Choose RabbitMQ if
- Multiple routing mechanisms
- Low complexity and flat learning curve
- Lightweight
- For medium or smaller companies
- Choose Kafka if
- Higher throughput
- Persistence of messages
- For large companies
If a message queue cannot preserve the order of messages on its own, how to keep messages delivered in order (FIFO).
- Solution 1: Add sequencing information into each message.
If there are duplicate messages in a message queue, how the receiver handles duplicate messages (Achieve exactly-once delivery guarantee from at-least-once delivery guarantee).
- Solution 1: Make the receiver idempotent.
- The receiver can process the same message multiple times without no additional effect.
- Solution 2: Track each message which has been processed into a data store and discard duplicates.
- Add a unique identifier into each message.
- Create a deduplication table on the consumer side to record which message has been processed.
- Add an unique index on the message identifier column in the deduplication table (the table will reject to insert a record whose message identifier value already exists in the table).
- Book: Chris R.(2018). Chapter 3. Interprocess communication in a microservice architecture, Microservices Patterns (pp. 65-109). Manning Publications
- Book: Neha N.,Gwen S.,Todd P.(2017). Chapter 7. Building Data Pipelines, Kafka: The Definitive Guide (pp. 135-156). O'Reilly Media
- Book: Martin K.(2017). Chapter 4 Encoding and Evolution, Designing Data-Intensive Applications (pp. 111-150). O'Reilly Media
- Web Article: Asynchronous Messaging Primer | https://docs.microsoft.com/en-us/previous-versions/msp-n-p/dn589781(v=pandp.10)
- CloudAMQP | Comparison: Apache Kafka VS RabbitMQ
- How to choose between Kafka and RabbitMQ