diagram.mmd — sequence
Worker Queue Processing sequence diagram

Worker queue processing is a messaging pattern where a Producer places work items into a Message Broker queue and one or more Worker processes consume and process those items asynchronously, with explicit acknowledgement ensuring at-least-once delivery.

What the diagram shows

This sequence diagram involves three participants: Producer (the application that creates work), Message Broker (e.g., RabbitMQ, SQS, Redis Streams), and Worker (the consumer process).

The flow illustrates:

1. Publish: the producer serializes a message (job payload) and publishes it to a named queue on the broker. The broker persists the message and acknowledges receipt. 2. Consume: the worker subscribes to the queue or polls it. The broker delivers a message to the worker and marks it as "in-flight" (invisible to other consumers for a visibility timeout period). 3. Process: the worker executes the job. If processing succeeds, the worker sends an explicit ACK (acknowledgement) to the broker, which permanently removes the message. 4. Negative acknowledgement: if processing fails, the worker sends a NACK or simply lets the visibility timeout expire. The broker returns the message to the queue for redelivery. 5. Competing consumers: multiple worker instances can consume from the same queue concurrently — the broker ensures each message is delivered to only one worker at a time (competing consumer pattern).

Why this matters

The explicit ACK/NACK protocol is what makes message queues reliable. Unlike a simple in-memory queue, a message is not lost if a worker crashes mid-processing — the visibility timeout causes it to reappear in the queue for another worker to claim.

For the full job lifecycle including retry budgets and dead letters, see Background Job Processing. For event streaming (as opposed to task queue) semantics, see Kafka Producer Consumer Flow. For time-triggered jobs, see Cron Job Scheduler.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

Worker queue processing is a messaging pattern where a producer places work items into a message broker queue and one or more worker processes consume and process those items asynchronously. The broker persists messages until they are explicitly acknowledged, ensuring work is not lost if a worker crashes mid-processing.
When the broker delivers a message to a worker, it marks the message as "in-flight" and starts a visibility timeout. If the worker processes the job successfully, it sends an explicit ACK — the broker permanently deletes the message. If the job fails, the worker sends a NACK or simply lets the visibility timeout expire — the broker returns the message to the queue for another worker to claim. This protocol guarantees at-least-once delivery.
Use a worker queue whenever the work to be done is too slow, too resource-intensive, or too failure-prone for synchronous request handling. Sending emails, processing uploads, calling unreliable external APIs, and performing batch data transformations are all good candidates. Queues also let you scale workers independently of the API tier — add more workers during peak load without changing the API.
A worker queue refers specifically to the message broker and consumer mechanics — the publish, consume, ACK/NACK protocol. A background job framework (like Sidekiq, Celery, or BullMQ) is a higher-level abstraction built on top of a queue that adds job serialization, retry configuration, dead-letter handling, scheduling, and monitoring UI. The worker queue is the infrastructure; the background job framework is the application layer that manages the full job lifecycle on top of it.
mermaid
sequenceDiagram participant P as Producer participant MB as Message Broker participant W1 as Worker 1 participant W2 as Worker 2 P->>MB: Publish message (job payload) MB-->>P: Acknowledge receipt MB->>MB: Persist message to queue W1->>MB: Poll for messages MB-->>W1: Deliver message (mark in-flight) W2->>MB: Poll for messages MB-->>W2: No messages available (locked by W1) W1->>W1: Process job alt Processing succeeds W1->>MB: ACK message MB->>MB: Remove message from queue W1-->>P: Job completed else Processing fails W1->>MB: NACK message MB->>MB: Return message to queue MB-->>W2: Deliver message to next available worker W2->>W2: Process job W2->>MB: ACK message MB->>MB: Remove message from queue end
Copied to clipboard