There has been a lot of talk lately about Command and Query Separation. One thing that has come up with many people in learning it is that they get confused between CQS [Meyer] and CQS [Architecture or DDD]. As such many have called for us to rename the latter to something different as although it is very similar to CQS [Meyer] they find it to be quite different. I however disagree with this let’s look at our definitions.
Separate command methods that change state from query methods that read state.
Separate command messages that change state from query messages that read state.
The reader should notice that these two are nearly identical, the principle has remained the same, only the definitions of what commands and queries are has changed. A really quick reader will also be quick to jump on me for not bringing in all of what CQS has come to be known as.
In CQS [Architecture/DDD/whatever] we also go one step further and we create two end points (or objects) by splitting the responsibilities of the original concept. We give one sub-concept the responsibility of processing all of the commands and another the responsibility of processing all of the queries. We do this because we have come to understand that there are very different non-functional requirements for each and that by separating the two we can better tailor solutions.
One question that has been hitting me is whether or not this is something that may work as a pattern at the object granularity as opposed to the endpoint as many of these types of patterns are relevant to both scopes.
This part is new and is not CQS [Meyer] I am going to throw out a quick pattern name for this and call it Command and Query Responsibility Segregation or CQRS as we are in fact simply taking what would usually be one object and splitting its responsibilities into two objects.
So the first step is that we apply CQS as a principle, and we then come through and apply the CQRS pattern in order to end up with what people are currently calling “CQS”. I would hope that this is a clearer explanation and manages to bring in the original intent of command and query separation while realizing that there is in fact an important difference.
Does this help clear things up or does it only make things more confusing?