Two popular queues: a flexible broker you run, and a managed queue in the cloud.
RabbitMQ and Amazon SQS are two of the most common message queues. Both let one part of your system drop a message in a line, so another part can pick it up later.
A message queue sits between a producer (who sends work) and a consumer (who does it). The producer does not wait. The queue keeps the message safe until a consumer is ready. (See Message Queues and Message Brokers for the basics.)
In RabbitMQ a producer does not write straight to a queue. It sends the message to an exchange. The exchange looks at the message's routing key and at the bindings (rules that link the exchange to queues), and then copies the message into every queue that matches. Consumers read from the queues, and the broker pushes messages to them.
With SQS you create a queue and send messages to it. There is no exchange. Consumers pull messages by asking the queue. When a consumer receives a message, SQS does not delete it. It hides it for a while (the visibility timeout). If the consumer deletes the message in time, the work is done. If it crashes or is too slow, the message becomes visible again and another consumer gets it.
| Exchange | How it routes | Typical use |
|---|---|---|
| Direct | Exact match of routing key and binding key | Send a job to one named queue, e.g. 'billing' |
| Topic | Pattern match on a dotted key: * is one word, # is zero or more words | order.paid, order.refund.*, or order.# for audit |
| Fanout | Copy to every bound queue, ignore the key | Broadcast an event to every interested service |
| Headers | Match on message headers instead of the key | Rare. Routing on several attributes at once |
| Type | Ordering | Duplicates | Throughput |
|---|---|---|---|
| Standard | Best effort. Order may differ from send order | At-least-once: a message may arrive twice | Very high, grows automatically |
| FIFO | Kept in order within a message group id | Deduplication window removes repeats of the same id | Lower limits than standard (check the current limits) |
| Question | RabbitMQ | SQS |
|---|---|---|
| Who runs it? | You (or a managed host) | AWS, fully managed |
| How are messages received? | Broker pushes to consumers (prefetch limits) | Consumers pull (long polling) |
| Routing | Exchanges, bindings, patterns | None: one queue per destination (pair with SNS for fan-out) |
| Acknowledgement | Ack, nack, requeue | Delete the message before the visibility timeout ends |
| Replication | Quorum queues copy data across nodes | Handled for you across zones |
| Protocols | AMQP and others (MQTT, STOMP via plugins) | AWS API over HTTPS |
| Dead letters | Dead-letter exchange, TTL | Dead-letter queue with a max receive count |
Topic patterns: * is exactly one word, # is zero or more words. The bindings above are a fixed teaching example.
exchange: orders (type: topic) queue billing <- binding "order.paid" queue audit <- binding "order.#" publish key "order.paid" -> billing, audit publish key "order.shipped" -> audit
| Term | Meaning in easy words |
|---|---|
| Producer / consumer | The side that sends messages, and the side that receives and processes them |
| Exchange | RabbitMQ's router: it receives messages and copies them to queues by rule |
| Binding | A rule that links an exchange to a queue, often with a key or pattern |
| Routing key | A label on a message (like order.paid) that the exchange uses to route it |
| Ack / nack | A consumer's reply: done (ack) or failed (nack, optionally put back) |
| Prefetch | How many unacknowledged messages RabbitMQ lets one consumer hold at once |
| Quorum queue | A RabbitMQ queue copied across several nodes, so it survives a node loss |
| Visibility timeout | The time SQS hides a received message, waiting for the consumer to delete it |
| Long polling | Waiting on the SQS server for messages to arrive, instead of returning empty at once |
| FIFO queue / message group | An SQS queue that keeps order inside each message group id |
| Dead-letter queue (DLQ) | A queue for messages that failed too many times |
| Choice | We gain | We lose |
|---|---|---|
| RabbitMQ | Routing control, protocols, low latency, can run anywhere | Operations work and capacity planning |
| SQS | No operations, huge scale, pay per use | Routing flexibility, and it is tied to AWS |
| SQS FIFO | Ordering per group and deduplication | Lower throughput than standard |
| Long visibility timeout | Fewer duplicate runs | A crashed job waits longer to be retried |
| Short visibility timeout | Fast retry after a crash | Slow jobs run twice at once |
| Big prefetch | Higher throughput | Uneven work and more messages redelivered after a crash |