Machine Room

Kafka vs RabbitMQ

Both carry messages between services. RabbitMQ is a queue: a message is done, then gone. Kafka is a log: a message stays after it's read. The one-page notes from the reel.

Download the PDF

One-page notes, Kafka vs RabbitMQ. Both carry messages between services. Only one of them really is a queue. 1, Why a broker. order service. email service. direct call. order service. message broker. email service. producer. consumer. A direct call: if the email service is slow or down, the order is stuck too. With a broker, the producer hands the message over and moves on. The message waits until the consumer is ready. 2, Kafka and RabbitMQ are both brokers. RabbitMQ. a queue. done, then gone. Kafka. a log. kept after it's read. "event streaming platform". Both get called message queues. The difference: what happens to a message after it is read. 3, RabbitMQ: a queue. 412, 413, 414. first in, first out. email service. ack. 1. RabbitMQ delivers 412 to the email service. 2. The email service sends the receipt and replies: an acknowledgement. 3. Only then does RabbitMQ delete 412. 4. Dies before it acknowledges? 412 goes back in the queue and is delivered again. "An ack(nowledgement) is sent back by the consumer to tell RabbitMQ that a particular message had been received, processed and that RabbitMQ is free to delete it.". 4, Kafka: a log. topic. 0, 1, 2, 3, 4. 410, 411, 412, 413, 414. written at the end. Each message is written at the end of the log. Kafka calls that log a topic. After it's read, it stays there. "events are not deleted after consumption.". 5, The offset: one number per consumer. 0, 1, 2, 3, 4. 410, 411, 412, 413, 414. 5. 0. email service. reports service. move back, read again. The offset is the position of the next message to read: "just a single integer, the offset of the next message to consume". The email service reads on from its offset. The reports service, added later, starts at the beginning and reads the whole week. "A consumer can deliberately rewind back to an old offset and re-consume data." Kafka's quickstart reads from 0 with --from-beginning. 6, Kept, but not forever. log.retention.hours = 168. 410, 411, 412, 413, 414. 7 days. By default, Kafka deletes messages after seven days (168 hours), read or not. RabbitMQ deletes a message when its job is acknowledged. A reports service added later finds this week's orders already gone. RabbitMQ can also copy one message into two queues for two services that already exist, and it has streams: an append-only log. 7, Which one?. RabbitMQ | Kafka. a message is | a job | a record. after it's read | deleted on the ack | kept, 7 days by default. who reads it | one consumer, done once | many services, now or later. Job, done once and then gone: RabbitMQ. Record that many services read: Kafka. A queue forgets what's done. A log keeps it, and every reader keeps its own place.

On a phone, press and hold the image to save it.