Message Queue Patterns
TL;DR
Core messaging patterns — competing consumers, scatter-gather, request-reply, message filter, and routing slip — solve recurring distributed communication challenges.
Explanation
Key patterns: (1) Competing consumers: multiple consumers on one queue, each processes different messages — horizontal scaling. (2) Scatter-gather: broadcast to multiple services, aggregate responses. (3) Request-reply: producer sends and waits for reply on a correlation ID — makes async look synchronous. (4) Message filter: consumer silectively processes messages matching criteria. (5) Dead letter: failed messages routed to DLQ. (6) Retry with backoff: failed processing retried with increasing delay. (7) Priority queue: high-priority messages processed first. (8) Message expiry: TTL after which message is discarded. These are from Enterprise Integration Patterns (Hohpe & Woolf).
Common Misconception
✗ Queues are just async function calls — queues enable complex patterns (scatter-gather, correlation, routing) far beyond simple async invocation.
Why It Matters
Knowing named patterns enables choosing the right approach and communicating architecture decisions precisely — 'use scatter-gather here' is clearer than describing it from scratch.
Common Mistakes
- Request-reply via queue without timeout — hangs forever if reply doesn't come.
- Competing consumers on an ordered queue — breaks message ordering.
- Priority queue without monitoring — high-priority messages don't help if consumers are busy.
Code Examples
✗ Vulnerable
// Request-reply without timeout/correlation:
$replyQueue = 'reply.' . uniqid();
$producer->send('service.requests', ['reply_to' => $replyQueue, 'data' => $data]);
$reply = $consumer->waitFor($replyQueue); // Hangs if service is down
✓ Fixed
// Request-reply with timeout and correlation ID:
$correlationId = Uuid::v4();
$producer->send('service.requests', [
'correlation_id' => $correlationId,
'reply_to' => 'my-service.replies',
'data' => $data,
]);
$reply = $consumer->waitFor('my-service.replies', $correlationId, timeout: 5);
if (!$reply) throw new ServiceTimeoutException();
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Views
34
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 9
Amazonbot 6
Google 4
Ahrefs 2
SEMrush 2
Unknown AI 1
ChatGPT 1
Also referenced
How they use it
crawler 24
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Medium
⚡ Quick Fix
Apply named patterns: competing consumers for scale, request-reply for sync-over-async, dead letter for failures, priority queue for urgency. Always add timeouts to request-reply.
📦 Applies To
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
Auto-detectable:
✗ No
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: High
Context: File