Architecture
Queue Systems Explained: RabbitMQ, Redis and SQS-Style Queues
By NileVPS Team · Published · 5 min read
اقرأ المقال بالعربيSome work does not belong inside a web request. Sending a welcome email, resizing an uploaded photo, generating a PDF invoice or calling a slow third-party API can take seconds, and making the user wait for it hurts both experience and capacity. A queue system lets your app write a small message saying "this needs doing" and return immediately, while separate worker processes pick up messages and do the work at their own pace. This guide explains the core concepts and how three common families of queues, RabbitMQ, Redis and SQS-style services, approach them.
Why use a queue
- Faster responses: the request only records the job, then replies.
- Smoothing spikes: a burst of 10,000 signups becomes a backlog that workers drain steadily, instead of 10,000 simultaneous email calls.
- Isolation: if the email provider is down, jobs wait in the queue instead of failing user requests.
- Independent scaling: add workers when the backlog grows, without touching web servers.
Core concepts
Producers, consumers and brokers
The producer (your web app) publishes a message. The broker (RabbitMQ, Redis, a managed queue) stores it. A consumer, or worker, receives it and processes it.
Acknowledgements
A worker should confirm a message only after finishing the work. If the worker crashes before acknowledging, the broker redelivers the message to another worker. This gives at-least-once delivery: a message is never silently lost, but it may be processed twice. That is why job handlers should be idempotent, meaning running them twice has the same effect as once (for example, check whether the email was already sent before sending).
Retries and dead-letter queues
When processing fails, the job is retried, ideally with growing delays. After a maximum number of attempts, it moves to a dead-letter queue (DLQ) where a human can inspect it. Without a DLQ, a single malformed message can be retried forever and block other work.
Ordering
With several workers, jobs finish out of order. If strict ordering matters, route related messages to the same partition or consumer.
RabbitMQ
RabbitMQ is a dedicated message broker implementing AMQP. Producers publish to exchanges, which route messages to queues according to bindings: direct (by routing key), topic (pattern matching such as orders.*), fanout (to every bound queue) and headers.
Install on Debian or Ubuntu and check queues:
sudo apt install rabbitmq-server
sudo systemctl enable --now rabbitmq-server
sudo rabbitmqctl list_queues name messages consumersKey settings to know:
- Declare queues as durable and publish messages as persistent so they survive a broker restart.
- Set a prefetch count (
basic.qos) so each worker holds only a few unacknowledged messages, which spreads load fairly. - Configure a dead-letter exchange on the queue with the
x-dead-letter-exchangeargument or a policy. - For replicated queues across nodes, use quorum queues.
RabbitMQ shines when you need flexible routing, many independent consumers and mature tooling.
Redis as a queue
Many apps already run Redis, so using it for jobs is attractive.
Lists are the simplest option: producers LPUSH, workers BRPOP. But a popped message is gone, so a worker crash loses it unless you use LMOVE (or BLMOVE) into a processing list and clean up yourself. Libraries such as Sidekiq, BullMQ, RQ and Laravel's Redis queue driver handle these details.
Streams add consumer groups and acknowledgements:
redis-cli XADD emails '*' to [email protected] template welcome
redis-cli XGROUP CREATE emails mailers 0 MKSTREAM
redis-cli XREADGROUP GROUP mailers worker-1 COUNT 10 BLOCK 5000 STREAMS emails '>'
redis-cli XACK emails mailers 1700000000000-0Unacknowledged entries stay in the pending list, and XAUTOCLAIM lets another worker take over messages that have been pending too long.
Remember that Redis keeps data in memory. Enable AOF persistence (appendonly yes) if losing recent jobs on restart is unacceptable, and size RAM for the worst-case backlog.
SQS-style queues
Amazon SQS and similar managed queues (and self-hosted tools that copy their model) work by polling. A worker receives a message, and the message becomes invisible to others for a visibility timeout. If the worker deletes it before the timeout, it is done. If not, it reappears for another worker. A redrive policy moves messages to a DLQ after a set number of receives.
The key tuning rule: the visibility timeout must be longer than your slowest job, or messages will be processed twice in parallel. Standard SQS queues are at-least-once with best-effort ordering; FIFO queues offer ordering within a message group and deduplication, with lower throughput limits.
Comparison
| Aspect | RabbitMQ | Redis (Lists/Streams) | SQS-style |
|---|---|---|---|
| Model | Push to consumers, AMQP routing | Lists or streams with consumer groups | Pull with visibility timeout |
| Routing | Exchanges, topics, fanout | Basic, done in code | One queue per purpose |
| Durability | Disk, replicated quorum queues | Memory plus optional AOF/RDB | Managed by the provider |
| Operations | Run and monitor a broker | Often already in your stack | No servers to manage |
| Good fit | Complex routing, many services | Simple jobs in existing Redis apps | Cloud-native apps |
Practical checklist
- Keep messages small: store the file or record elsewhere and put its ID in the message.
- Make handlers idempotent and give each job a unique ID.
- Configure retries with backoff and a dead-letter queue from day one.
- Monitor queue depth and age of the oldest message; alert when they keep growing.
- Run workers under systemd or Supervisor with automatic restart.
- Stop workers gracefully on deploy so in-flight jobs finish or return to the queue.
A broker and a few workers fit comfortably on a small VPS at first, and you can move workers to their own server as load grows; see the pricing page for sizes. For why queues pair well with stateless web servers, read stateful vs stateless apps.
FAQ
Do I need RabbitMQ if I already have Redis?
Not necessarily. For background jobs in a single application, a Redis-backed library is often enough. RabbitMQ becomes worthwhile when you need complex routing, several independent consumer services or stronger durability guarantees.
What is the difference between a queue and pub/sub?
In a queue, each message is processed by one worker. In pub/sub, each message is delivered to every subscriber. RabbitMQ fanout exchanges and Redis Streams with multiple consumer groups can provide both styles.
Why are some jobs processed twice?
Most queues guarantee at-least-once delivery. A worker that crashes, or exceeds the visibility timeout before acknowledging, causes redelivery. Design jobs to be idempotent so duplicates are harmless.