DEV Community

Cover image for Kafka vs RabbitMQ vs SQS: Which Message Queue Should You Pick in a System Design Interview?
ScaleDojo
ScaleDojo

Posted on Edited on

Kafka vs RabbitMQ vs SQS: Which Message Queue Should You Pick in a System Design Interview?

Almost every system design answer includes the line "we'll put a queue here." The follow-up is always "which one, and why?"

"Kafka, because it's popular" is not an answer. Let's build a better one.

Why queues exist

A message queue decouples producers from consumers. It absorbs traffic spikes, lets services fail independently, and enables retries. The three most common choices behave quite differently.

The quick comparison

Kafka

  • Model: distributed log

  • Message retention: kept for days or weeks, replayable

  • Ordering: per partition

  • Throughput: very high

  • Routing: topics and partitions

  • Ops effort: high (self-managed)

RabbitMQ

  • Model: message broker

  • Message retention: removed after consumption

  • Ordering: per queue (with caveats)

  • Throughput: moderate to high

  • Routing: rich (exchanges, routing keys)

  • Ops effort: medium

Amazon SQS

  • Model: managed queue

  • Message retention: removed after consumption (retention window applies)

  • Ordering: FIFO queues only

  • Throughput: high, auto-scaled

  • Routing: basic

  • Ops effort: very low (fully managed)

Kafka: the replayable log

Kafka stores messages in an append-only log split into partitions. Consumers track their own position (offset), so they can replay old events.

Choose Kafka when you need:

Very high throughput
Event streaming or event sourcing
Multiple independent consumers reading the same stream
Replay for debugging or rebuilding state

Producer sketch:

from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers="localhost:9092")
producer.send("orders", key=b"user_42", value=b'{"order_id": 101}')
producer.flush()
Enter fullscreen mode Exit fullscreen mode

The key decides the partition, so all events for user_42 stay in order.

RabbitMQ: the flexible router

RabbitMQ routes messages through exchanges to queues based on rules. It supports acknowledgments, priorities, and delayed delivery.

Choose RabbitMQ when you need:

  • Complex routing logic

  • Task queues with per-message acknowledgment

  • Lower volume with richer delivery features

Consumer sketch:

import pika

conn = pika.BlockingConnection(pika.ConnectionParameters("localhost"))
channel = conn.channel()
channel.queue_declare(queue="emails", durable=True)

def handle(ch, method, props, body):
    print("sending email:", body)
    ch.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_consume(queue="emails", on_message_callback=handle)
channel.start_consuming()
Enter fullscreen mode Exit fullscreen mode

SQS: the zero-ops option

SQS is fully managed. You don't run servers, and it scales automatically. Standard queues give at-least-once delivery with best-effort ordering. FIFO queues give ordering and deduplication at lower throughput.

Choose SQS when you need:

  • A simple work queue with minimal operations

  • You are already on AWS

  • You don't need replay or complex routing

Decision guide

Ask these questions in order:

  1. Do consumers need to replay old messages or read the same stream independently? Kafka.

  2. Do you need complex routing or per-message priorities? RabbitMQ.

  3. Do you want the least operational work on AWS? SQS.

  4. Is volume huge and ordering per key important? Kafka.

Mini example: order processing

An e-commerce order triggers payment, inventory, email, and analytics.

  • Publish order_created to Kafka, so analytics and fraud services can each consume it, and replay if a bug is found.

  • Use SQS or RabbitMQ for the email task queue, since each email is a one-off job that is deleted after it is sent.

Using more than one queue technology is fine if each choice is justified.

What to say about delivery guarantees

Most systems give at-least-once delivery, so duplicates can happen. Always mention that consumers should be idempotent, meaning processing the same message twice has the same effect as once. This one sentence separates strong answers from average ones.

Common mistakes

  1. Choosing Kafka for a tiny task queue.

  2. Forgetting consumer idempotency.

  3. Ignoring ordering requirements.

  4. Not mentioning a dead-letter queue for failed messages.

  5. Saying "exactly-once" without explaining the cost.

If you want to rehearse choices like these, a hands-on system design interview prep platform lets you work through real scenarios instead of memorizing tables.

Top comments (0)