Definition
What it is
A queue is a data structure and a communication pattern. As a data structure, it is a first-in-first-out list: items enter at the tail and leave at the head. As a pattern, it sits between two independent processes — a producer that emits messages and a consumer that processes them — and holds the messages until the consumer is ready. The producer does not need to know which consumer will process the message, whether the consumer is running, or how fast it processes. The consumer does not need to know how many producers exist or how bursty they are. The queue absorbs the difference in pace between the two sides.
In modern infrastructure, "queue" almost always refers to a message queue system: RabbitMQ, AWS SQS, Apache Kafka, Google Pub/Sub, Redis Streams, ActiveMQ. Each has its own guarantees about delivery (at-most-once, at-least-once, exactly-once), ordering, and durability, but all of them solve the same structural problem. A task queue (Celery, Sidekiq, BullMQ) is a specialization: instead of raw messages, it carries jobs — references to a handler plus arguments — and runs them in a separate worker process.
Why it matters
Without a queue, the producer and consumer are coupled. If the consumer is down, the producer fails. If the producer sends a burst of a thousand requests, the consumer must process all of them at the same rate or lose them. If the consumer is slow, the producer blocks. Each of those couplings is a source of cascading failure in production. The queue removes all three: the producer enqueues and moves on, the consumer drains at its own pace, and a burst fills the queue instead of the consumer.
Queues are also the substrate for reliability patterns: retries with backoff, circuit breakers, and idempotency all assume a queue that can hold a message until it is safely processed. When a downstream service fails, the queue holds; when it recovers, the queue drains. That is what makes asynchronous systems able to survive partial outages.
How it works
The mechanism differs slightly across systems, but the shape is uniform. The producer serializes a message and sends it to a queue endpoint. The queue persists the message and makes it available for consumption. A consumer receives one or more messages, processes them, and acknowledges. On ack, the queue deletes the message. If the consumer fails before acking, the queue makes the message available again after a visibility timeout — that is what "at-least-once delivery" means in practice.
graph LR P[Producer] -->|send| Q[Queue] Q -->|deliver| C[Consumer] C -->|ack| Q C -->|nack / timeout| Q Q -->|too many retries| DLQ[Dead Letter Queue]
Delivery guarantees define what happens when things go wrong. At-most-once means the message may be lost but is never processed twice. At-least-once means it may be processed twice but is never lost. Exactly-once is the theoretical ideal, but in practice it requires transactional coordination between producer, queue, and consumer, and the cost is usually high enough that most teams settle for at-least-once plus idempotent consumers. The choice is not a preference; it is a design decision driven by what the system can afford to get wrong.
Designing a queue-based pipeline
Pick the delivery guarantee deliberately
At-least-once with idempotent consumers is the practical default. Exactly-once only when the business genuinely cannot tolerate duplicates, and the cost is justified.
Bound the queue
Set a maximum queue size, a retention period, and a backlog alert. An unbounded queue is a silent failure waiting to happen.
Configure a dead letter queue
Every message that fails N times should land in a DLQ, not be retried forever. DLQs are the input to human investigation; without them, poison messages block the pipeline.
Make consumers idempotent
Given at-least-once delivery, consumers will see duplicates. Design every consumer to tolerate them: dedupe keys, upserts, or explicit state checks.
Horizontal scaling is part of the design. Multiple producers can write to the same queue without coordination. Multiple consumers can read from the same queue, and the queue distributes messages among them (competing consumers pattern). That is what allows the pipeline to absorb load by adding consumers, without touching producers. In partitioned systems like Kafka, the distribution is stricter: messages with the same key go to the same partition, and each partition is consumed by exactly one consumer within a group, which preserves order per key at the cost of a fixed consumer count per topic.
Common failures
A second failure is unbounded backlog. When a consumer falls behind and nothing alerts on queue depth, the backlog grows until the retention period expires and messages are silently dropped. The fix is monitoring: alert on queue depth, on consumer lag, and on the age of the oldest unconsumed message. These three signals detect most backlog incidents before data loss.
A third failure is missing idempotency. In at-least-once delivery, the queue will occasionally deliver the same message twice: after a consumer crash, after a visibility timeout, after a network blip. A consumer that writes to a database without deduplication produces duplicate rows. A consumer that sends an email without deduplication sends it twice. Every non-idempotent side effect must be paired with a deduplication mechanism: an upsert, a message ID check, or a transactional outbox.
Origin
The word comes from the Latin cauda, "tail", through the Old French cue, meaning a line of waiting people or vehicles. In computer science, queues as a data structure appear in the earliest operating systems (the IBM 7090 in 1959 had job queues). The distributed message queue emerged as a separate pattern in the 1990s with IBM MQSeries (1993) and TIBCO Rendezvous, but it was Gregor Hohpe and Bobby Woolf's Enterprise Integration Patterns (2003) that codified message queues as a design vocabulary. AWS Simple Queue Service (SQS, 2004) turned the pattern into a cloud primitive. RabbitMQ (2007) made it open-source infrastructure. Kafka (2011) rethought it as an append-only log.
Messaging enables distributed communication that is loosely coupled. A sender sends a message to a channel, and the receiver picks it up. Neither needs to know about the other.
— Hohpe, G. & Woolf, B., *Enterprise Integration Patterns*, 2003
Evidence
FAQ
- What is the difference between a queue and a topic?
A queue delivers each message to one consumer. A topic delivers each message to every subscribed consumer. Queues are for distributing work (competing consumers); topics are for broadcasting events (fan-out). Pub/sub systems like Google Pub/Sub or AWS SNS offer both, often combined: a topic fans out to multiple queues, and each queue delivers to one consumer per message.
- What is exactly-once delivery and why is it hard?
Exactly-once means each message is processed precisely once, no duplicates and no losses. Achieving it requires transactional coordination across producer, queue, and consumer, which is expensive in latency and complexity. In practice, most systems achieve "at-least-once delivery plus idempotent processing", which produces exactly-once effects at the cost of writing every consumer idempotently.
- Should I use a queue or a database as a work queue?
A database can act as a queue (jobs table with status column), and for low volume it is perfectly fine. At higher volume, database queues suffer from lock contention, polling overhead, and poor throughput. Purpose-built queues (SQS, RabbitMQ, Kafka) are designed for the throughput and durability requirements of production messaging. The right answer depends on scale: start with a database if volume is modest; move to a dedicated queue when the volume justifies the operational cost.
- How do I handle a poison message?
Configure a maximum retry count and a dead letter queue. After N failed attempts, the queue moves the message to the DLQ instead of retrying forever. The DLQ is monitored separately; humans investigate and either fix the message and re-inject it, or discard it. Without a DLQ, a single malformed message can block an entire pipeline.
- What is backpressure and how does it relate to queues?
Backpressure is the mechanism by which a system signals its inability to accept more work. In a queue-based pipeline, backpressure takes the form of a growing backlog: as the queue fills, either the producer slows down, the queue rejects new messages, or the backlog grows until it triggers an alert. Configuring backpressure correctly means deciding which of those three behaviors is acceptable, per queue.
Connections
● broader ● narrower ● related
Used in the garden
- From Script to Microservice: Scaling Reporting Automation to 10K Daily Requests (11×)
- Changelog (2×)
- Architecting API Dominance: Design a REST API That Scales From Day One (2×)
- Serverless Savings: Cut Cloud Costs by 40% with Elegant Patterns (1×)
- The Savvy Entrepreneur's Secret: 10 FREE Web Apps That Will Skyrocket Your Digital Business (1×)
- Unlock Real-Time Power: Vanilla JS & SSE for Elite Dashboards (1×)
Sources
Hohpe, G. & Woolf, B. (2003). Enterprise Integration Patterns. Addison-Wesley. https://www.enterpriseintegrationpatterns.com/
RabbitMQ (2024). AMQP 0-9-1 Model Explained. https://www.rabbitmq.com/tutorials/amqp-concepts.html
AWS (2024). Amazon Simple Queue Service. https://aws.amazon.com/sqs/
Google Cloud (2024). Cloud Pub/Sub Overview. https://cloud.google.com/pubsub/docs/overview
Richardson, C. (2024). Pattern: Messaging. microservices.io. https://microservices.io/patterns/communication-style/messaging.html
Etymology
Origin: borrowed
queue(noun): from Old French cue, a line of waiting people or vehiclescauda(noun): Latin for "tail"; the root behind queue and cue
Semantic network
● broader ● narrower ● related
Used in the garden
- From Script to Microservice: Scaling Reporting Automation to 10K Daily Requests (11×)
- Changelog (2×)
- Architecting API Dominance: Design a REST API That Scales From Day One (2×)
- Serverless Savings: Cut Cloud Costs by 40% with Elegant Patterns (1×)
- The Savvy Entrepreneur's Secret: 10 FREE Web Apps That Will Skyrocket Your Digital Business (1×)
- Unlock Real-Time Power: Vanilla JS & SSE for Elite Dashboards (1×)
Sources
Hohpe, G. & Woolf, B. (2003). Enterprise Integration Patterns. https://www.enterpriseintegrationpatterns.com/
RabbitMQ (2024). AMQP 0-9-1 Model Explained. https://www.rabbitmq.com/tutorials/amqp-concepts.html
AWS (2024). Amazon Simple Queue Service. https://aws.amazon.com/sqs/
Google Cloud (2024). Cloud Pub/Sub Overview. https://cloud.google.com/pubsub/docs/overview
{"Richardson, C. (2024). Pattern":"Messaging. https:\/\/microservices.io\/patterns\/communication-style\/messaging.html"}