Synchronous execution of expensive operations blocks the user and degrades responsiveness. Direct point-to-point integration between services creates tight coupling and makes systems brittle under load spikes.
Message queues receive, hold, and deliver messages asynchronously — a publisher sends a job, a worker picks it up later, and the user is not blocked. This decouples producers from consumers and provides a buffer during traffic spikes.
- Application (publisher) sends a job message to the queue.
- Queue acknowledges receipt immediately.
- Application notifies the user of job status (“processing”).
- A worker (consumer) picks up the job from the queue.
- Worker processes the job and signals completion.
Popular implementations: Redis (simple, high throughput, messages can be lost), RabbitMQ (AMQP, managed delivery guarantees), and SQS (fully hosted, at-least-once delivery, may deliver duplicates).
- Asynchronous processing — producers never wait for consumers
- Decouples producers and consumers (they don’t need to know about each other)
- Buffers messages during traffic spikes, preventing producer overload
- Worker-based processing enables horizontal scaling of consumers
- Different reliability guarantees (at-most-once, at-least-once, exactly-once)
- Related: Task Queues — message queues focus on message delivery; task queues focus on scheduling and executing compute work
- Related: Back Pressure — queue growth beyond capacity triggers back pressure mechanisms
- Related: Microservices Architecture — queues enable loose coupling between services
- Related: Write-Behind Cache — both use async processing patterns to decouple operations
- Message ordering: Most queues do not guarantee strict FIFO ordering under high concurrency. Use a FIFO queue or sequence IDs if order matters.
- Duplicate messages: At-least-once delivery guarantees can result in duplicate processing. Workers should be idempotent.
- Poison pills: Malformed messages that cause workers to fail repeatedly can block the queue. Implement dead-letter queues to isolate them.