← All patterns The problem A feed query repeatedly joins write-oriented records. The read shape and write invariants need different models.
When it fits Read and write requirements differ enough to justify separate interfaces/models and the extra update coordination.
The whole architecture
Architecture diagram Download SVG Separate command and query interfaces use an asynchronously maintained read model in this variant.
Blue arrows are API/data calls; purple arrows carry committed projection input.
cqrs materialized views architecture Separate command and query interfaces use an asynchronously maintained read model in this variant. Blue arrows are API/data calls; purple arrows carry committed projection input. Command model Query model client → command: command client → query: query command → write: commit write → feed: committed changes feed → projector: apply projector → read: maintain view query → read: query command query commit committed changes apply maintain view query A successful command and a fresh projected query are different guarantees. Clients Commands and queries The write model enforces the business operation. Command API Validate write invariants The query contract should define freshness and read-your-write behavior. Query API Read-oriented contract CQRS can also use shared physical storage; separate stores are an option. Write store Authoritative records Projection input must correspond to committed changes. Committed feed Change position / identity Replayed or out-of-order records need an explicit application policy. Projector Version-aware updates This store can be rebuilt from an appropriate source boundary. Read model Derived query state CQRS does not inherently require event sourcing. Projection operations Lag, checkpoints, rebuild and read-your-write policy API / data call Event / job flowSelect a component, or focus it and press Enter, to read its role.
This shows an asynchronous materialized-view implementation of CQRS. Physical store separation and event sourcing are independent choices. Walk through the design
Follow one operation Core flow Failure & recovery
Select a step to highlight its participants. This conceptual walkthrough is separate from challenge scoring.
Arrows show the conceptual relationships used by this walkthrough.
1 Accept a command2 Update a projection3 Serve queriesStep 1 of 3 Accept a command Validate an invariant and commit authoritative state through the command interface.
← Previous Restart Next step →
Trade-offs to make explicit CQRS can use one database; separate storage and event sourcing are optional choices. Materialized views speed a query by maintaining derived data. Their freshness and rebuild cost become explicit concerns. Failure modes to plan for A delayed projection can hide a successful write from the next query. Define read-your-write behavior. Out-of-order changes or replayed deletes can corrupt a projection without version and tombstone handling. Before you build Explain your decision After a command succeeds, should the UI wait for projection progress, read authoritative state, or show a pending state?
Use Plan & estimate inside practice to record your assumptions and trade-offs.
These links open the original challenges. Existing round unlocks, completions and points apply.
The celebrity post Practice query-oriented materialization and push/pull/hybrid trade-offs.
Open challenge → Rebuild search while writes continue Practice rebuilding derived state from a snapshot and committed changes.
Open challenge → Further reading Microsoft · CQRS ↗
Original PractiseGrid explanations and conceptual diagrams, with primary references for further study. Dedicated scored exercises can be added as coverage grows.