Prompt
I need to decouple web requests from slow work, what queue pattern should I use?
Latest observation
For decoupling web requests from slow work, the usual choice is a work queue / background job queue pattern.
Recommended pattern
- Web request does only the fast part:
- validate input
- persist a record or enqueue a job
- return quickly, usually
202 Acceptedor200 OKwith a job ID
- Background worker(s) process the slow task asynchronously:
- send emails
- generate reports
- resize images
- call slow external APIs
- run long computations
Common queue styles
-
Work Queue (competing consumers)
Best for most async web tasks. Multiple workers pull jobs from one queue, and each job is processed once. -
Task Queue with retries / dead-letter queue
Use when jobs can fail and need retrying. Add:- retry policy with backoff
- dead-letter queue for poison messages
-
Delayed queue / scheduled jobs
Use if work should happen later, not immediately. -
Outbox pattern + queue
Best when you need reliable delivery from your web app to the queue and want to avoid losing jobs if the app crashes after DB write but before enqueue.
Practical guidance
Use a durable message queue such as:
- RabbitMQ
- Amazon SQS
- Google Pub/Sub
- Azure Service Bus
- Kafka if you need event streaming at scale
If you’re just starting, the simplest reliable setup is:
- Web app writes job record to DB
- Worker polls DB or consumes from queue
- Client gets job ID and checks status later
Rule of thumb
- If the user doesn’t need the result immediately: async work queue
- If the task must be done exactly once: queue + idempotent worker + retries
- If enqueue reliability matters: outbox pattern
If you want, I can recommend a concrete pattern based on your stack (e.g., Node, Python, Java, .NET, AWS, etc.).