← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Message Queue Patterns

messaging Intermediate

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();

Added 23 Mar 2026
Views 34
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 2 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 2 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Perplexity 9 Amazonbot 6 Google 4 Ahrefs 2 SEMrush 2 Unknown AI 1 ChatGPT 1
crawler 24 crawler_json 1
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

✓ schema.org compliant