Solution

The CQRS pattern is like the CQS pattern with one major distinction – CQS pattern defines commands and queries as different methods within a type, whereas, the CQRS pattern defines commands and queries on different objects.

What this distinction means is that you can implement CQS in your applications by separating commands and queries as separate methods in a class, while retaining the same processing model to process both the models. CQRS, on the other hand completely separates the processing of commands and queries. Thus, the two patterns vary in scopes. The scope of the CQRS pattern is a bounded context, while the scope of CQS is a single class:

Structure of CQRS system

The preceding diagram presents the structure of a CQRS system. Users can submit commands to system which are stored in the command store and receive immediate feedback from the system. A user can check the status of progress of his commands through the user interface. A process will asynchronously move commands from the command store to the command queue, from where they will be picked by appropriate command handlers that will process the record and update the current state of data in the database.

Although not necessary, a CQRS system typically uses two separate physical databases for reads and writes so that they can be scaled independently. The read and write databases need not even have the same structure, for example, your application may write to a relational database such as SQL server whereas the reads operations are served through a document database such as MongoDB or Azure Cosmos DB. There are several approaches that can help synchronize the data in the read database and the write database. In case, the two databases have different structure, in case of failure of the read database, the state may be restored by replaying commands from the command store.

Responsibility of data validations is an important part of the CQRS pattern. The user interface should only be responsible for basic validations such as numeric values in phone number field, the business validations should be part of the domain logic and should be handled by the command handler.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.207.164