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

Pub/Sub Pattern

Messaging Beginner
debt(d8/e7/b7/t7)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d8), detection_hints.automated is no — missed events from offline subscribers using Redis SUBSCRIBE only surface when users notice missing behavior, slightly better than d9 because code review can flag SUBSCRIBE usage.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7), quick_fix says switch from Redis SUBSCRIBE to Redis Streams or Kafka — that's a broker swap touching every publisher and subscriber, plus redesigning events to be idempotent and self-contained.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7), applies_to spans web/cli/queue-worker — once event-driven decoupling is adopted, every feature is shaped by the publish/subscribe contract and topic design.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), misconception explicitly says devs conflate pub/sub with queues, and Redis SUBSCRIBE 'looks like' durable pub/sub but silently drops messages for offline subscribers — contradicts the mental model of queues.

About DEBT scoring →

TL;DR

Pub/Sub (Publish-Subscribe) decouples senders from receivers — publishers emit events to topics, all interested subscribers receive them without knowing each other.

Explanation

Publisher sends to a Topic/Channel — it doesn't know who's listening. Subscribers declare interest in topics. Broker delivers to all active subscribers. Implementations: Redis PUBLISH/SUBSCRIBE, Kafka topics, RabbitMQ fanout exchange, SNS+SQS (AWS), Google Pub/Sub. Difference from point-to-point queue: queue delivers to ONE consumer; pub/sub delivers to ALL subscribers. Use cases: event broadcasting (user registered → email + analytics + audit + recommendation all receive it), real-time feeds (dashboard updates). Fan-out: one event → many independent handlers. Redis pub/sub doesn't persist — subscribers miss messages while offline; use Redis Streams for durability.

Common Misconception

Pub/Sub and message queues are the same — pub/sub broadcasts to all subscribers; queues deliver to one consumer. Redis SUBSCRIBE delivers to active subscribers only; Kafka delivers to all consumer groups including future ones.

Why It Matters

Pub/Sub enables truly decoupled event-driven architecture — a new subscriber can be added without changing the publisher, enabling independent feature development.

Common Mistakes

  • Using Redis SUBSCRIBE for durable events — messages are lost if subscriber is offline.
  • Publishing events that are too granular — hundreds of tiny events create consumer overhead.
  • Not considering message ordering when multiple publishers write to the same topic.

Code Examples

✗ Vulnerable
// Redis SUBSCRIBE — volatile, lost if offline:
$redis->subscribe(['user.registered'], function($redis, $channel, $msg) {
    sendWelcomeEmail($msg); // Missed if worker was down during publish
});
✓ Fixed
// Redis Streams — durable pub/sub:
$redis->xadd('user.events', '*', ['event' => 'registered', 'user_id' => $id]);

// Consumer group reads with acknowledgement:
$msgs = $redis->xreadgroup('email-group', 'worker-1', ['user.events' => '>']);
foreach ($msgs['user.events'] as $id => $fields) {
    sendWelcomeEmail($fields['user_id']);
    $redis->xack('user.events', 'email-group', $id);
}

Added 23 Mar 2026
Views 68
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping 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 3 pings S 4 pings S 3 pings M 0 pings T 2 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 2 pings T 0 pings W 1 ping T 0 pings F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 9 Amazonbot 8 Google 8 Perplexity 7 SEMrush 5 ChatGPT 4 Unknown AI 3 Ahrefs 3 Claude 2 Bing 2 PetalBot 2 Meta AI 1
crawler 49 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Medium
⚡ Quick Fix
Use Redis Streams (not SUBSCRIBE) for durable pub/sub. Use Kafka for high-throughput multi-subscriber events. Design events to be self-contained and idempotent.
📦 Applies To
web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
publish|subscribe|dispatch
Auto-detectable: ✗ No
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant