RabbitMQ
RabbitMQ is an open-source message broker. Producers send messages to it, it routes each message into one or more queues according to rules you define, and it pushes messages from those queues to consumers, tracking each one until the consumer acknowledges it. It's written in Erlang, implements the AMQP 0-9-1 protocol natively (plus AMQP 1.0, MQTT and STOMP), and has been one of the most widely deployed brokers for well over a decade.
The properties that define it:
- Smart broker, simple consumers: routing logic lives in the broker. Producers publish to an exchange with a routing key, and the broker decides which queues get a copy. Consumers just read from a queue.
- Per-message acknowledgement: the broker tracks every delivered message until the consumer acks it. Unacked messages are redelivered if the consumer dies, and rejected ones can be dead-lettered.
- Push delivery with flow control: the broker pushes messages to consumers, limited by a prefetch count, so a slow consumer isn't flooded.
- Flexible features per queue: TTLs, length limits, priorities, dead-letter exchanges, and several queue types with different durability and performance trade-offs.
- Low latency at moderate scale: sub-millisecond to a few milliseconds per message when queues are short, at throughputs on the order of tens of thousands of messages per second per queue.
In interviews, RabbitMQ is a natural fit for task queues and for routing messages between services by type or topic: "send this to the email workers," "route order.eu.* events to the EU fulfilment service," "fan this alert out to every subscriber." It also comes up when an interviewer asks you to compare brokers, because it's the classic contrast to Kafka: a queue that forgets messages once they're processed versus a log that keeps them. This post covers how RabbitMQ works and when to choose it.
The Core Concepts
RabbitMQ's model has more moving parts than a plain queue, and they're the vocabulary you'll use in an interview.
Producer: publishes messages. A producer never writes to a queue directly. It publishes to an exchange, with a routing key (a string like order.created.eu).
Exchange: a routing table. It receives messages and decides which queues they go to, based on its type and its bindings. It doesn't store anything; if no queue matches, the message is dropped (or returned to the producer if it asked).
Queue: an ordered buffer that stores messages until a consumer acknowledges them. This is where messages actually live.
Binding: a rule connecting an exchange to a queue, usually with a binding key: "messages to exchange orders with routing key matching order.*.eu go to queue eu-fulfilment."
Consumer: subscribes to a queue and receives messages pushed by the broker over a channel (a lightweight virtual connection multiplexed over one TCP connection).
Virtual host (vhost): a namespace for exchanges, queues and permissions, so several applications or tenants can share one cluster without seeing each other's objects.
Exchange Types
The exchange type is what gives RabbitMQ its routing power:
| Type | Routes a message to | Typical use |
|---|---|---|
| Direct | Queues whose binding key equals the routing key exactly | Task queues by job type: resize, transcode |
| Topic | Queues whose binding pattern matches the routing key (* = one word, # = zero or more) |
order.*.eu, logs.#.error |
| Fanout | Every bound queue, ignoring the routing key | Broadcast: cache invalidation, notifications |
| Headers | Queues whose binding matches message header values | Routing on several attributes at once |
There's also a default exchange, a direct exchange that every queue is automatically bound to by its own name. Publishing to it with routing key emails puts the message in the emails queue. That's what makes RabbitMQ look like a simple queue in the hello-world examples.
In the diagram, an order.created.eu message published to the orders topic exchange goes to the EU fulfilment queue (bound with order.*.eu) and the audit queue (bound with #), but not to the US queue. One publish, two copies, and the producer doesn't know or care who's listening.