Event Sourcing vs Messaging
debt(d9/e7/b7/t7)
Closest to 'silent in production until users hit it' (d9). The detection_hints field explicitly states automated: no, and the code pattern hints (EventStore|appendEvent|DomainEvent) merely identify event sourcing usage, not whether it was chosen for the wrong reasons. There is no tool that can detect an architectural category mistake — choosing event sourcing where simple messaging suffices is invisible until the system is in production and the complexity overhead becomes a maintenance and performance burden.
Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix advises using event sourcing only where genuinely needed, but reversing that choice after adoption means replacing the persistence strategy, rebuilding projections, removing CQRS scaffolding, and redesigning inter-service communication patterns. This is not a single-component fix — it touches storage, domain models, query layers, and service boundaries across the codebase.
Closest to 'strong gravitational pull' (b7). The tags (event-sourcing, cqrs, architecture) and applies_to (web, cli, queue-worker) indicate this is a system-wide architectural choice. Once event sourcing is adopted, every future change — new features, schema migrations, query optimization, service additions — is shaped by the event store, projection model, and versioning requirements. The common_mistakes (no versioning, no CQRS) confirm the persistent productivity tax imposed on all maintainers.
Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception field explicitly states the canonical wrong belief: developers conflate event sourcing (a persistence strategy) with messaging (a communication strategy), treating them as alternatives rather than complements. This is a well-documented architectural confusion where the 'obvious' interpretation — both deal with events, so they solve the same problem — directly contradicts reality, leading to significant wrong architectural choices.
TL;DR
Explanation
Event sourcing: the event log IS the database — current state is derived by replaying events. No UPDATE/DELETE, only append. Benefits: full audit trail, time travel, event replay, projections. Kafka can serve as the event store. Messaging: events are transient notifications between services — usually not the source of truth. Combining: store events with event sourcing (for your domain), publish to a message broker for other services. CQRS + Event Sourcing: command side appends events, query side builds projections from event stream. PHP: EventSauce, Prooph, Broadway libraries.
Common Misconception
Why It Matters
Common Mistakes
- Using event sourcing where a simple audit log suffices — add complexity without benefit.
- Not versioning events — events are forever, schemas change.
- Event sourcing without CQRS — query performance degrades without read projections.
Code Examples
// Treating messaging as event sourcing — no persistence:
$broker->publish('user.updated', $event); // If broker goes down, history lost
// Event sourcing — events ARE the state:
$user->applyEvent(new UserEmailChanged($userId, $newEmail));
$eventStore->append($user->getDomainEvents()); // Persistent, immutable
// Then publish to broker for other services:
foreach ($user->getDomainEvents() as $event) {
$broker->publish($event);
}