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

Event Bus Patterns

messaging PHP 7.0+ Intermediate
debt(d5/e5/b7/t7)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan and psalm as the tools, and the code_pattern describes string event names vs typed classes and missing type-hints — these are precisely the kinds of issues that static analysis tools catch but default linters and compilers miss. The automated flag is yes, but only with specialist configuration.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix describes moving to typed event classes (e.g. Symfony EventDispatcher with named event classes), but common_mistakes reveal deeper issues: cross-service communication misuse, missing error handling in listeners, synchronous slow operations, and missing Outbox Pattern. Correcting a single misuse (string → class) is a small refactor, but fixing architectural misuse (in-process for cross-service, adding outbox pattern) touches multiple files and components — overall e5 fits.

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

Closest to 'strong gravitational pull' (b7). The applies_to covers all three contexts (web, cli, queue-worker) and the tags include 'architecture'. An event bus choice shapes how all decoupled operations are wired together across the codebase — every new feature that needs async or decoupled behaviour must conform to the chosen event bus pattern. Misusing in-process vs broker compounds over time as more listeners accumulate, making migration progressively harder.

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

Closest to 'serious trap' (t7). The misconception field explicitly states that developers confuse in-process event buses with message brokers — treating them as interchangeable. This contradicts how similar concepts (e.g. RabbitMQ, Kafka) behave elsewhere: in-process buses are synchronous and transactional while brokers are async with eventual consistency. The common_mistakes reinforce this: lost events on crash, uncaught exceptions rolling back transactions, and synchronous slow operations blocking requests are all consequences of this fundamental confusion.

About DEBT scoring →

Also Known As

event dispatcher event listener pub/sub Symfony EventDispatcher

TL;DR

Patterns for routing events between publishers and subscribers — in-process event buses (Symfony EventDispatcher), message broker buses (RabbitMQ, Kafka), and hybrid architectures.

Explanation

In-process event bus: events dispatched and handled synchronously within a single PHP request. Useful for domain event handling where all subscribers run in the same process. PHP implementations: Symfony EventDispatcher, Laravel Event/Listener, league/event. Message broker bus: events serialised and sent to RabbitMQ/Kafka/SQS, consumed by separate worker processes asynchronously. Hybrid: raise in-process domain events, then publish integration events to the broker via the Outbox Pattern. The choice depends on: consistency requirements, cross-service communication needs, and latency tolerance.

Common Misconception

In-process event buses and message brokers are interchangeable — in-process buses are synchronous and transactional with the main operation; message brokers are async and require eventual consistency handling.

Why It Matters

An in-process event bus that sends emails synchronously makes the checkout request wait for the email server — using a message broker decouples the email from the checkout transaction entirely.

Common Mistakes

  • In-process event bus for cross-service communication — events are lost if the process crashes.
  • No error handling in event listeners — uncaught exceptions in listeners can roll back the main transaction.
  • Synchronous slow operations in event listeners — database queries and HTTP calls block the request.
  • Not using the Outbox Pattern for guaranteed delivery to a message broker.

Code Examples

✗ Vulnerable
// In-process listener doing slow work synchronously:
class OrderPlacedListener {
    public function handle(OrderPlaced $event): void {
        $this->emailService->sendConfirmation($event->order); // Slow SMTP call
        $this->smsService->send($event->order);               // External HTTP call
        $this->analyticsService->track($event->order);        // Another HTTP call
        // Checkout response delayed by all three operations
    }
}
✓ Fixed
// Separate concerns: in-process vs async:
// In-process: fast, transactional operations only
class OrderPlacedListener {
    public function handle(OrderPlaced $event): void {
        // Fast — just queue jobs for async processing:
        SendConfirmationEmail::dispatch($event->orderId)->onQueue('notifications');
        UpdateInventory::dispatch($event->orderId)->onQueue('inventory');
        // Checkout completes immediately
    }
}

// Async queue workers handle the slow operations independently

Added 16 Mar 2026
Edited 22 Mar 2026
Views 24
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 2 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 2 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 7 Perplexity 4 Google 4 Ahrefs 2 Unknown AI 2 ChatGPT 2 SEMrush 1 Bing 1
crawler 19 crawler_json 4
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Use a typed event bus (Symfony EventDispatcher, Laravel Events) with named event classes rather than magic strings — type safety and IDE autocomplete prevent typos in event names
📦 Applies To
PHP 7.0+ web cli queue-worker laravel symfony
🔗 Prerequisites
🔍 Detection Hints
String event names 'order.created' instead of OrderCreated class; event listeners not type-hinted; no event discovery
Auto-detectable: ✓ Yes phpstan psalm
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant