Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

RabbitMQ & Traditional Queues

Traditional message broker with flexible routing

RabbitMQ is a traditional message broker that implements the AMQP (Advanced Message Queuing Protocol) standard. Unlike Kafka’s log-based approach, RabbitMQ uses a more traditional broker model where messages are delivered to consumers and then removed from queues (unless configured otherwise).

RabbitMQ’s architecture revolves around four key components:

  1. Exchanges - Receive messages from producers and route them to queues based on routing rules
  2. Queues - Store messages until they are consumed
  3. Bindings - Define the relationship between exchanges and queues (routing rules)
  4. Routing Keys - Message attributes used by exchanges to determine routing

This design provides flexible routing capabilities that Kafka doesn’t offer natively. RabbitMQ excels at scenarios requiring complex routing logic, task distribution, and point-to-point messaging.

Diagram
  1. Exchange - Receives messages from producers and routes them to queues based on routing rules. Think of it as a post office that sorts mail.
  2. Queue - Stores messages until they are consumed. Messages are removed after successful consumption (unless configured otherwise).
  3. Binding - Defines the connection between an exchange and a queue, including the routing key pattern that determines which messages go to which queue.
  4. Routing Key - A message attribute that the exchange uses to determine which queue(s) should receive the message. It’s like an address on an envelope.

The Flow: Producer → Exchange (with routing key) → Binding (matches routing key) → Queue → Consumer

This design allows for flexible routing - you can route the same message to multiple queues, filter messages based on patterns, or broadcast to all queues, depending on the exchange type.


Routes to queue with matching routing key.

Diagram

Use case: Point-to-point messaging, task queues

Routes based on pattern matching (wildcards).

Diagram

Patterns:

  • * - Matches one word
  • # - Matches zero or more words

Use case: Categorized messages, event routing

Broadcasts to all bound queues (ignores routing key).

Diagram

Use case: Pub-sub, notifications, cache invalidation

Routes based on message headers (ignores routing key).

Use case: Complex routing logic



Critical for reliable message processing.

# Message removed immediately when delivered
channel.basic_consume(queue='orders', on_message_callback=callback, auto_ack=True)

Problem: If consumer crashes, message lost!

# Message removed only after ack
def callback(ch, method, properties, body):
process_message(body)
ch.basic_ack(delivery_tag=method.delivery_tag) # Acknowledge
channel.basic_consume(queue='orders', on_message_callback=callback, auto_ack=False)

Benefits:

  • Message redelivered if consumer crashes
  • Can reject and requeue on error
  • Reliable processing

FeatureRabbitMQKafka
ModelTraditional brokerStreaming platform
Message RetentionRemoved after consumptionRetained (configurable)
RoutingFlexible (exchanges)Simple (topics/partitions)
OrderingPer queuePer partition
ThroughputGoodExcellent
Use CaseTask queues, RPCEvent streaming, logs

Choose RabbitMQ when:

  • Need flexible routing
  • Task queues
  • Message removed after processing
  • Complex routing logic

Choose Kafka when:

  • Event streaming
  • High throughput
  • Message retention needed
  • Replay capability needed

Exchanges Route

Exchanges route messages to queues based on routing keys. Direct, topic, fanout, headers.

Manual Ack

Use manual acknowledgment for reliability. Auto-ack removes messages immediately (risky).

Durability

Make queues/exchanges/messages durable to survive broker restart. Critical for production.

Flexible Routing

RabbitMQ’s flexible routing (exchanges) makes it great for complex routing scenarios.