Skip to main content
17

Queues vs streams (RabbitMQ/SQS vs Kafka)

MediumMessagingKafkaQueues

What's the difference between a message queue (RabbitMQ, SQS) and an event stream (Kafka)? When do you use each?

TL;DR

Both decouple producers from consumers and absorb load spikes. A message queue distributes tasks: each message is processed by one consumer and then deleted. It's ideal for background jobs like sending emails or resizing images. An event stream is an append-only, replayable log: messages stay for a retention period, and many independent consumer groups each read the whole stream at their own position (offset). It's ideal for event-driven architecture, analytics pipelines, and feeding several services from the same events.

Key points

Queue (RabbitMQ, SQS)Stream (Kafka, Kinesis)
After consumptionMessage removedMessage kept until retention
ConsumersCompeting workers share the workEach group gets every message
ReplayNoYes, by resetting the offset
OrderingUsually none (FIFO queues exist)Per partition
ScalingAdd workersAdd partitions (one consumer per partition per group)
  • Delivery is usually at-least-once, so consumers must be idempotent (dedupe by message ID).
  • Messages that keep failing go to a dead-letter queue (DLQ) after N retries.
  • Kafka ordering: use a partition key (such as orderId) so all events for one entity are ordered.
  • Transactional outbox: write the event to an outbox table in the same DB transaction as the data change, then publish it. This avoids "saved to DB but the event was lost".

Example

  • Queue: POST /signup → enqueue send-welcome-email → one worker sends it.
  • Stream: OrderPlaced → billing, inventory, analytics and notifications each consume it independently, and a new service can replay history.

Common follow-ups

  • Is exactly-once delivery possible? End-to-end, not really. Use at-least-once delivery plus idempotent processing.
  • What's backpressure? When consumers fall behind, the queue grows. Watch consumer lag and scale consumers or slow producers.

What interviewers look for

Tip

Delete-after-processing vs a retained log, competing consumers vs consumer groups, and idempotency plus DLQs for failures.

  • Red flag: assuming exactly-once delivery and ignoring duplicate messages.

Was this helpful?