Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CQRS is an architectural pattern that separates the models for reading and writi

CQS is a simple concept—it is about methods within the same object being either queries or commands. Each method either returns state or mutates state, but not both. Even a single repository pattern object can comply with CQS. CQS can be considered a foundational principle for CQRS.

[Command and Query Responsibility Segregation (CQRS)](https://martinfowler.com/bliki/CQRS.html) was introduced by Greg Young and strongly promoted by Udi Dahan and others. It is based on the CQS principle, although it is more detailed. It can be considered a pattern based on commands and events plus optionally on asynchronous messages. In many cases, CQRS is related to more advanced scenarios, like having a different physical database for reads (queries) than for writes (updates). Moreover, a more evolved CQRS system might implement [Event-Sourcing (ES)](http://codebetter.com/gregyoung/2010/02/20/why-use-event-sourcing/) for your updates database, so you would only store events in the domain model instead of storing the current-state data. However, this is not the approach used in this guide; we are using the simplest CQRS approach, which consists of just separating the queries from the commands.
[Command and Query Responsibility Segregation (CQRS)](https://martinfowler.com/bliki/CQRS.html) was introduced by Greg Young and strongly promoted by Udi Dahan and others. It is based on the CQS principle, although it is more detailed. It can be considered a pattern based on commands and events plus optionally on asynchronous messages. In many cases, CQRS is related to more advanced scenarios, like having a different physical database for reads (queries) than for writes (updates). Moreover, a more evolved CQRS system might implement [Event-Sourcing (ES)](https://martinfowler.com/eaaDev/EventSourcing.html) for your updates database, so you would only store events in the domain model instead of storing the current-state data. However, this is not the approach used in this guide; we are using the simplest CQRS approach, which consists of just separating the queries from the commands.

The separation aspect of CQRS is achieved by grouping query operations in one layer and commands in another layer. Each layer has its own data model (note that we say model, not necessarily a different database) and is built using its own combination of patterns and technologies. More importantly, the two layers can be within the same tier or microservice, as in the example (ordering microservice) used for this guide. Or they could be implemented on different microservices or processes so they can be optimized and scaled out separately without affecting one another.

Expand All @@ -29,6 +29,11 @@ An example of this kind of service is the ordering microservice from the eShopOn

The application layer can be the Web API itself. The important design aspect here is that the microservice has split the queries and ViewModels (data models especially created for the client applications) from the commands, domain model, and transactions following the CQRS pattern. This approach keeps the queries independent from restrictions and constraints coming from DDD patterns that only make sense for transactions and updates, as explained in later sections.

## Additional resources

- **Greg Young. Versioning in an Event Sourced System** (Free to read online e-book) \
<https://leanpub.com/esversioning/read>

>[!div class="step-by-step"]
>[Previous](index.md)
>[Next](eshoponcontainers-cqrs-ddd-microservice.md)
>[Next](eshoponcontainers-cqrs-ddd-microservice.md)
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ As stated, use domain events to explicitly implement side effects of changes wit
## Additional resources

- **Greg Young. What is a Domain Event?** \
<http://codebetter.com/gregyoung/2010/04/11/what-is-a-domain-event/>
<https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf#page=25>

- **Jan Stenberg. Domain Events and Eventual Consistency** \
<https://www.infoq.com/news/2015/09/domain-events-consistency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,12 @@ There is only one application architecture: the architecture of the system or en
- **Martin Fowler. CQRS** \
<https://martinfowler.com/bliki/CQRS.html>

- **Greg Young. CQS vs. CQRS** \
<http://codebetter.com/gregyoung/2009/08/13/command-query-separation/>

- **Greg Young. CQRS Documents** \
[https://cqrs.files.wordpress.com/2010/11/cqrs\_documents.pdf](https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf)

- **Greg Young. CQRS, Task Based UIs and Event Sourcing** \
<http://codebetter.com/gregyoung/2010/02/16/cqrs-task-based-uis-event-sourcing-agh/>
<https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf>

- **Udi Dahan. Clarified CQRS** \
<http://udidahan.com/2009/12/09/clarified-cqrs/>

- **Event-Sourcing (ES)** \
<http://codebetter.com/gregyoung/2010/02/20/why-use-event-sourcing/>

>[!div class="step-by-step"]
>[Previous](apply-simplified-microservice-cqrs-ddd-patterns.md)
>[Next](cqrs-microservice-reads.md)