The Command Query Responsibility Separation pattern
introduces a logical separation between read and write operations within a
distributed application. There are several reasons for and benefits that
result from this separation, as well as some application design implications.
Typically, the CQRS pattern is implemented by introducing the concept of
message queues into an application, eliminating the need for direct access to
the central data store for write operations for the application.
The intent of CQRS is to allow the individual nodes in a
distributed application (assuming it is a web-based application, these would be
the web servers) to handle user requests with a minimum of interaction with or
dependency on difficult-to-scale resources (most often, the central data store,
but also other resources such as sending emails). This is can be achieved by
creating a local read-only copy of the data the individual node requires (for
Queries) and introducing a reliable messaging system that can handle writes
(for Commands) in an offline, asynchronous fashion. As individual user
requests come into the server, it reads data from its local store, and writes
any Commands to its local message queue (which is then picked up and handled
outside of the web application and its limited pipeline). The result is a huge
increase in performance and scalability for the web node, since there is no
longer synchronous, transactional access to a single, shared data store
involved in each request.