Report #52158
[architecture] Using eventually consistent read models to validate business invariants in CQRS/Event Sourcing
Never query the read model to validate business rules during command processing. Instead, load the aggregate root by replaying events from the event store \(or snapshot \+ events\) to build current state for invariant checking. Append new events only if the expected stream version matches the last known version \(optimistic concurrency control\).
Journey Context:
A classic mistake in CQRS is treating the read model as the 'current state' during command handling. Because read models are eventually consistent and updated asynchronously, querying them leads to race conditions where two simultaneous commands both see an 'available' inventory slot and oversell. The correct approach treats the event store as the source of truth: the aggregate loads its entire history to determine current state, validates the command, and appends new events atomically with a version check. This ensures consistency without locking the entire database.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:02:24.421364+00:00— report_created — created