{"schemaVersion":"1.0","type":"TechArticle","types":["Article","TechArticle"],"slug":"how-message-queues-work-kafka-vs-rabbitmq-l1bqu","url":"https://zyvop.com/how-message-queues-work-kafka-vs-rabbitmq-l1bqu","title":"How Message Queues Work: Kafka vs RabbitMQ","subtitle":"A visual guide to how message queues work, how Kafka and RabbitMQ differ, and a simple framework for choosing the right one for your system.","tldr":"Kafka and RabbitMQ both move messages between services, but in very different ways. This guide explains exchanges, queues, partitions, and offsets with diagrams, covers new features like Kafka share groups and RabbitMQ streams, and helps you choose the right tool.","keywords":["Kafka","Event Streaming","Message Queues","Distributed Systems","RabbitMQ","Backend"],"entities":["Alysaa Lissy","Kafka","Event Streaming","Message Queues","Distributed Systems","RabbitMQ","Backend","ZyVOP"],"keyTakeaways":["Kafka and RabbitMQ are the two names that come up whenever services need to talk to each other asynchronously.","They look similar from a distance, but they start from different ideas: RabbitMQ is a message broker that routes messages into queues, while Kafka is a distributed log that stores an ordered stream of events.","Those differences have also been narrowing."],"headings":["1. What a Message Queue Does","Delivery guarantees","2. How RabbitMQ Works: The Smart Broker","Exchange types","The life of a message","Queue types in RabbitMQ 4.x","A minimal example (Python, pika)","3. How Kafka Works: The Distributed Log","The ideas that matter","Offsets and at-least-once","Durability settings","Kafka as a queue: share groups","A minimal example (Python, confluent-kafka)","4. Kafka vs RabbitMQ Side by Side","5. Which Should You Choose?","6. Reliability Checklist","Final Thoughts"],"outboundLinks":[],"contentText":"Kafka and RabbitMQ are the two names that come up whenever services need to talk to each other asynchronously. They look similar from a distance, but they start from different ideas: RabbitMQ is a message broker that routes messages into queues, while Kafka is a distributed log that stores an ordered stream of events. Those differences have also been narrowing. RabbitMQ added a replicated log (streams), and Kafka added queue-style consumption (share groups). This post explains how each one works and where the real differences remain. Versions: This post reflects Apache Kafka 4.3.x and RabbitMQ 4.4.x as of November 2026. Both have changed a lot recently, so older comparisons may be out of date. 1. What a Message Queue Does A message queue sits between a producer (which sends messages) and a consumer (which processes them). The producer hands the message to the broker and moves on; the consumer picks it up when it's ready. flowchart LR subgraph W[\"Without a queue\"] A1[\"Order service\"] --&gt;|\"direct call\"| B1[\"Email service\"] B1 -.-&gt;|\"down or slow:&lt;br/&gt;order fails too\"| A1 end subgraph Q[\"With a queue\"] A2[\"Order service\"] --&gt; M[\"Message queue&lt;br/&gt;holds messages safely\"] M --&gt; B2[\"Email service&lt;br/&gt;processes when ready\"] endQueues give you: Decoupling: services don't need to be online at the same time. Buffering: traffic spikes pile up in the queue instead of crashing consumers. Retries: failed work can be delivered again. Scaling: add more consumers to process messages faster. Delivery guarantees Guarantee Meaning Risk At-most-once Delivered zero or one time Messages can be lost At-least-once Retried until acknowledged Messages can be duplicated Exactly-once The effect happens once Hard to achieve end to end Both systems are typically run at-least-once, so consumers should be idempotent: processing the same message twice must be safe. 2. How RabbitMQ Works: The Smart Broker In RabbitMQ, publishers never write to a queue directly. They publish to an exchange, which routes each message to one or more queues using rules called bindings. The broker then delivers messages from queues to subscribed consumers, and removes each one once the consumer acknowledges it. flowchart LR P[\"Publisher&lt;br/&gt;routing key: order.created.eu\"] --&gt; X[\"Topic exchange\"] X --&gt;|\"binding: order.created.*\"| Q1[\"Queue A&lt;br/&gt;match\"] X --&gt;|\"binding: order.*.*\"| Q2[\"Queue B&lt;br/&gt;match\"] X --&gt;|\"binding: payment.*\"| Q3[\"Queue C&lt;br/&gt;no match\"] Q1 --&gt; C1[\"Consumer\"] Q2 --&gt; C2[\"Consumer\"]Exchange types Type Routes by Typical use Direct Exact routing key match Task routing, log levels Fanout Ignores the key; copies to every bound queue Broadcasts, notifications Topic Pattern match (* is one word, # is zero or more words) Flexible event routing Headers Message header values Attribute-based routing A built-in default exchange routes by queue name, which is why simple examples seem to publish straight to a queue. The life of a message flowchart TD A[\"Publisher sends message&lt;br/&gt;to an exchange\"] --&gt; B[\"Exchange routes using bindings\"] B --&gt; C{\"Any matching queue?\"} C -- No --&gt; D[\"Dropped, or returned to the&lt;br/&gt;publisher if flagged mandatory\"] C -- Yes --&gt; E[\"Stored in queue&lt;br/&gt;publisher confirm sent\"] E --&gt; F[\"Delivered to a consumer&lt;br/&gt;up to the prefetch limit\"] F --&gt; G{\"Consumer result\"} G -- \"ack\" --&gt; H[\"Message removed\"] G -- \"nack with requeue,&lt;br/&gt;or consumer crash\" --&gt; I[\"Requeued\"] I --&gt; J{\"Delivery limit&lt;br/&gt;reached?\"} J -- No --&gt; F J -- Yes --&gt; K[\"Dead-lettered or dropped\"]Key mechanics: Consumer acknowledgements: if a consumer's connection drops before it acks, RabbitMQ requeues the message for another consumer. Publisher confirms: the broker tells the publisher when it has taken responsibility for a message. Prefetch: limits how many unacknowledged messages a consumer holds, which spreads work fairly. Dead-lettering: rejected or repeatedly failing messages can be sent to a dead-letter exchange. Quorum queues have a default redelivery limit of 20. Queue types in RabbitMQ 4.x Type Storage and replication Consumption Classic Local; not replicated (mirroring was removed in 4.0) Destructive Quorum Replicated with Raft; the choice when data safety matters Destructive Stream Replicated append-only log Non-destructive, with replay Recent releases keep improving quorum queues. RabbitMQ 4.3 added 32 strict priority levels and native delayed retries. A minimal example (Python, pika) import json import pika conn = pika.BlockingConnection(pika.ConnectionParameters(\"localhost\")) ch = conn.channel() # Topology: a topic exchange and a replicated (quorum) queue bound to it ch.exchange_declare(exchange=\"orders\", exchange_type=\"topic\", durable=True) ch.queue_declare(queue=\"email-service\", durable=True, arguments={\"x-queue-type\": \"quorum\"}) ch.queue_bind(queue=\"email-service\", exchange=\"orders\", routing_key=\"order.created.*\") # Publish with confirms enabled ch.confirm_delivery() ch.basic_publish( exchange=\"orders\", routing_key=\"order.created.eu\", body=json.dumps({\"order_id\": 42}), properties=pika.BasicProperties(delivery_mode=2), # 2 = persistent mandatory=True, ) # Consume with manual acks and a prefetch limit def handle(channel, method, properties, body): send_email(json.loads(body)) # your work here channel.basic_ack(delivery_tag=method.delivery_tag) ch.basic_qos(prefetch_count=10) ch.basic_consume(queue=\"email-service\", on_message_callback=handle) ch.start_consuming()3. How Kafka Works: The Distributed Log Kafka stores messages (called records) in topics. Each topic is split into partitions, and each partition is an append-only log. Records are not deleted when read. They stay until the retention period expires (7 days by default), and every record has an offset, its position in the partition. flowchart LR PR[\"Producer&lt;br/&gt;key: customer-42\"] --&gt;|\"key decides partition\"| T subgraph T[\"Topic: orders\"] P0[\"Partition 0\"] P1[\"Partition 1\"] P2[\"Partition 2\"] end subgraph GA[\"Consumer group A: email service\"] A1[\"Consumer 1\"] A2[\"Consumer 2\"] end subgraph GB[\"Consumer group B: analytics\"] B1[\"Consumer 3\"] end P0 --&gt; A1 P1 --&gt; A1 P2 --&gt; A2 P0 --&gt; B1 P1 --&gt; B1 P2 --&gt; B1The ideas that matter Partitions give parallelism. Records with the same key go to the same partition, so ordering is guaranteed within a partition, not across a whole topic. Consumer groups share the work. Within one group, each partition is read by at most one consumer, so parallelism is capped by the partition count. Each group tracks its own position, so many groups can read the same topic independently. Consumers pull. They poll the broker for records and remember their offset. Replication: each partition has a leader and follower replicas. Since Kafka 4.0, the cluster runs on KRaft with no ZooKeeper. Every group keeps its own bookmark in the same log: flowchart LR subgraph P[\"Partition 0: append-only log\"] O0[\"offset 0\"] --&gt; O1[\"offset 1\"] --&gt; O2[\"offset 2\"] --&gt; O3[\"offset 3\"] --&gt; O4[\"offset 4&lt;br/&gt;newest\"] end GA[\"Group A:&lt;br/&gt;next read is offset 3\"] -.-&gt; O3 GB[\"Group B:&lt;br/&gt;next read is offset 1\"] -.-&gt; O1 W[\"Producer appends here\"] -.-&gt; O4Because the log isn't consumed destructively, a new service can start from offset 0 and replay history, or a bug fix can reprocess old events. Offsets and at-least-once Consumers normally commit their offset after processing. If one crashes before committing, it restarts from the last committed offset, so some records are processed twice: flowchart LR A[\"poll: fetch records from&lt;br/&gt;last committed offset\"] --&gt; B[\"Process records\"] B --&gt; C[\"Commit offset\"] C --&gt; A B -.-&gt;|\"crash before commit\"| D[\"Restart:&lt;br/&gt;re-read from last commit\"] D --&gt; ADurability settings For data you can't lose, Kafka needs deliberate configuration: replication.factor=3 and min.insync.replicas=2 on the topic. Both default to 1. acks=all on the producer, so a write is confirmed only after the in-sync replicas have it. enable.idempotence=true, so producer retries can't create duplicates. It's on by default in the Java client since Kafka 3.0. Transactions plus isolation.level=read_committed on consumers for exactly-once processing inside Kafka. Side effects outside Kafka, like sending an email, still need idempotent handling. Kafka as a queue: share groups Kafka's classic consumer groups tie parallelism to partitions and don't acknowledge individual records. Kafka 4.2 made share groups (\"Queues for Kafka\") production-ready. In a share group: Many consumers can share a topic, and there can be more consumers than partitions. Each record is acknowledged individually: accepted, released for redelivery, or rejected. Delivery attempts are counted, so unprocessable records stop being retried. Per-partition ordering is not guaranteed, so use share groups for independent tasks, not ordered streams. At the time of writing, built-in dead-letter support for share groups is still pending. A minimal example (Python, confluent-kafka) import json from confluent_kafka import Producer, Consumer # Producer: durable settings producer = Producer({ \"bootstrap.servers\": \"localhost:9092\", \"acks\": \"all\", \"enable.idempotence\": True, }) producer.produce(\"orders\", key=\"customer-42\", value=json.dumps({\"order_id\": 42})) producer.flush() # Consumer: commit the offset only after processing succeeds consumer = Consumer({ \"bootstrap.servers\": \"localhost:9092\", \"group.id\": \"email-service\", \"auto.offset.reset\": \"earliest\", \"enable.auto.commit\": False, }) consumer.subscribe([\"orders\"]) while True: msg = consumer.poll(1.0) if msg is None: continue if msg.error(): print(msg.error()) continue send_email(json.loads(msg.value())) # your work here consumer.commit(message=msg, asynchronous=False)4. Kafka vs RabbitMQ Side by Side Here's one \"order created\" event handled by each system: flowchart LR subgraph R[\"RabbitMQ\"] RP[\"Producer\"] --&gt; RE[\"Topic exchange\"] RE --&gt;|\"order.created\"| RQ1[\"Queue: email\"] RE --&gt;|\"order.created\"| RQ2[\"Queue: inventory\"] RQ1 --&gt; RC1[\"Email consumer&lt;br/&gt;ack removes message\"] RQ2 --&gt; RC2[\"Inventory consumer&lt;br/&gt;ack removes message\"] end subgraph K[\"Kafka\"] KP[\"Producer\"] --&gt; KT[\"Topic: orders&lt;br/&gt;log kept until retention expires\"] KT --&gt; KG1[\"Group: email&lt;br/&gt;own offset\"] KT --&gt; KG2[\"Group: inventory&lt;br/&gt;own offset\"] KT --&gt; KG3[\"Group: analytics&lt;br/&gt;can replay from offset 0\"] end RabbitMQ Kafka Core model Broker with exchanges and queues Distributed commit log Routing Rich: direct, fanout, topic, headers Topic and partition key; consumers choose topics Delivery to consumers Broker pushes to subscribers (prefetch limit) Consumers pull with poll After consumption Message removed on ack (queues) Record stays until retention expires Replay Not with queues; yes with streams Yes, by resetting offsets Ordering Per queue; competing consumers and requeues can reorder processing Per partition Scaling consumers Add competing consumers to a queue Up to the partition count per group (more with share groups) Per-message handling Acks, nacks, dead-lettering, TTL, priorities, delayed retries Offset commits; per-record acks only in share groups Replication Quorum queues and streams (Raft) Partition replicas with leader and followers Protocols AMQP 0-9-1, AMQP 1.0, MQTT, STOMP Kafka's own binary protocol In short: RabbitMQ is a smart broker with simple consumers (the broker tracks each message), while Kafka is a simple log with smart consumers (each consumer tracks its position). Throughput is the other classic difference. Kafka's batched, append-only design is built for very high volume, and RabbitMQ's own documentation says its queue types can't compete with log-based systems on raw throughput, which is why it added streams. In practice, always benchmark your own workload. 5. Which Should You Choose? flowchart TD S[\"What do you need?\"] --&gt; Q1{\"Replay old events, or many independent&lt;br/&gt;services reading the same stream?\"} Q1 -- Yes --&gt; Q2{\"Already run RabbitMQ,&lt;br/&gt;with moderate volume?\"} Q2 -- Yes --&gt; R1[\"RabbitMQ streams can work\"] Q2 -- No --&gt; K1[\"Kafka\"] Q1 -- No --&gt; Q3{\"Flexible routing, priorities, delayed&lt;br/&gt;retries, or per-message handling?\"} Q3 -- Yes --&gt; R2[\"RabbitMQ\"] Q3 -- No --&gt; Q4{\"Very high volume, stream processing,&lt;br/&gt;or data pipelines?\"} Q4 -- Yes --&gt; K2[\"Kafka\"] Q4 -- No --&gt; Q5{\"Simple background job queue?\"} Q5 -- Yes --&gt; R3[\"RabbitMQ, or Kafka share groups&lt;br/&gt;if you already run Kafka\"] Q5 -- No --&gt; R4[\"Either works: pick what your team&lt;br/&gt;already knows how to operate\"]Choose RabbitMQ when you need task queues, complex routing, request/reply, priorities, or delayed retries, and you want each message handled and then gone. Choose Kafka when you need an event backbone: high throughput, replayable history, stream processing, or many consumers reading the same events. Use both when it fits. Many systems run Kafka for event streams and RabbitMQ for task queues. 6. Reliability Checklist RabbitMQ Use quorum queues (or streams) for data you can't lose; classic queues in 4.x aren't replicated. Publish persistent messages and enable publisher confirms. Use manual acks with a prefetch limit. Set up dead-lettering or a delivery limit for poison messages. Make consumers idempotent. Kafka Set replication factor 3, min.insync.replicas=2, and acks=all. Keep the idempotent producer enabled. Commit offsets only after processing, and make consumers idempotent. Choose partition keys carefully, and plan partition counts early: changing them later can break per-key ordering. Final Thoughts RabbitMQ and Kafka both move messages between services, but they model messages differently. In RabbitMQ a message is a unit of work to be routed, delivered, and removed. In Kafka a message is an event in a shared log that anyone can read, and re-read. With RabbitMQ streams and Kafka share groups, either can now cover much of the other's territory. Choose based on the center of gravity of your workload (task distribution or event streaming), and on which system your team can operate confidently.","contentHash":"sha256:c4ea445fa0ab1e26d0dfff438f8b7034fb4c75a1f069d27281367db59c485095","authorName":"Alysaa Lissy","authorUrl":"https://zyvop.com/author/alysaa","authorSameAs":[],"category":"Backend","tags":["Kafka","Event Streaming","Message Queues","Distributed Systems","RabbitMQ"],"audience":"Software engineers and developers building applications with Backend","tone":"Instructional, practical, code-first","readingTimeMinutes":9,"wordCount":2208,"faqs":null,"primaryTopic":"Backend","publishedAt":"2026-11-23T04:39:48.964Z","updatedAt":"2026-11-23T04:39:48.964Z","canonicalUrl":"https://zyvop.com/how-message-queues-work-kafka-vs-rabbitmq-l1bqu"}