RabbitMQ
A traditional message broker that routes messages through exchanges to queues using bindings, with acknowledgements and flexible work-queue patterns.
By Ratish Jain · Updated
Definition
RabbitMQ is a message broker built on the AMQP model. Producers publish to an exchange, which uses bindings and routing keys to decide which queues receive a copy. Consumers pull from queues and send an ack once a message is safely processed, at which point the broker removes it.
Why It Exists
Services need to hand off work asynchronously without knowing who processes it or when. RabbitMQ acts as a smart intermediary that buffers work, spreads it across workers, and applies rich routing logic. Unlike a raw log, it takes responsibility for delivery: it tracks acks, redelivers on failure, and removes messages once done — behaving like a reliable task queue.
How It Works
Exchange types decide routing: direct matches an exact routing key, topic matches wildcard patterns, fanout broadcasts to all bound queues, and headers matches on attributes. Messages sit in a queue until a consumer takes one; with a prefetch limit and manual acks, work is fairly distributed across many workers (a work queue). If a consumer dies before acking, the message is requeued. Unroutable or repeatedly failed messages can go to a dead-letter exchange.
What It's Used For
- Background job and task queues (email, thumbnails, reports)
- Request/reply and RPC between services
- Complex routing where different message types fan to different consumers
- Rate-smoothing bursts of work across a worker pool
- Priority queues and delayed/scheduled delivery
Tradeoffs
- Flexible, powerful routing via exchange types
- Per-message acks, retries, priorities, and TTLs
- Great for distributing discrete tasks to workers
- Mature tooling and management UI
- Lower throughput than Kafka's log design
- No built-in long-term replay — messages leave on ack
- Queue depth pressure can degrade the broker
- Ordering guarantees weaken with multiple consumers/redelivery
When to Use / Avoid
- Use when
- You need task queues, complex routing, priorities, or reliable per-message delivery with acks.
- Avoid when
- You need very high-throughput streaming or long-term replay of an event history — use Kafka.
- Real-world
- Widely used for background jobs at companies like Reddit and Instagram, and by many Celery-based Python stacks.
Interview Questions
An exchange receives published messages and applies routing rules; a queue stores messages for consumers. Bindings connect exchanges to queues, so publishers never address queues directly.
With manual acks and durable queues plus persistent messages: the broker keeps the message until an ack arrives, and requeues it for another worker if the connection drops.
- →Publish to exchange, route via bindings to queues, consume with acks.
- →Exchange types: direct, topic, fanout, headers.
- →Messages are removed on ack — it's a queue, not a replayable log.
- →Work queues distribute tasks across a worker pool via prefetch.
- →Choose it for routing and task queues; Kafka for streaming.
Related
Everything on Archprimer is connected — follow the graph.