What is CQRS? Well if we ask google it will say "did you mean CARS?" (although it seems for developers who search a lot it now actually comes up.

According to http://www.all-acronyms.com/CQRS CQRS is Commercial Quality Rimmed Steel

 

CQRS is none of these things. CQRS is not new. One of my favorite questions I get from people is "How many real systems are there running with this kind of CQRS stuff". The answer is ten if not hundreds of thousands. It even funnier when asked about Event Sourcing as I actually worked on a system 10 years ago using Event Sourcing (it used to be really popular).

 

CQRS is pretty much MVC!

 

I have had very few people notice this when teaching but occasionally a bright one will pick up on it. Of course CQRS is not precisely MVC but it is definitely a variant. Let's go way back to 1979 and look at what Trygve had to say about MVC. http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf

 

 

MODELS

Models represent knowledge. A model could be a single object (rather uninteresting), or it

could be some structure of objects. The proposed implementation supports knowledge

represented in something resembling semantic nets (If I understand Laura correctly)

There should be a one-to-one correspondence between the model and its parts on the one

hand, and the represented world as perceived by the owner of the model on the other hand.

The nodes of a model should therefore represent an identifiable part of the problem.

The nodes of a model should all be on the same problem level, it is confusing and considered

bad form to mix problem-oriented nodes (e.g. calendar appointments) with implementation

details (e.g. paragraphs).

 

VIEWS

A view is a (visual) representation of its model. It would ordinarily highlight certain attributes

of the model and suppress others. It is thus acting as a presentation filter.

A view is attached to its model (or model part) and gets the data necessary for the presentation

from the model by asking questions. It may also update the model by sending appropriate

messages. All these questions and messages have to be in the terminology of the model, the

view will therefore have to know the semantics of the attributes of the model it represents. (It

may, for example, ask for the model's identifier and expect an instance of Text, it may not

assume that the model is of class Text.)

The main difference when we talk about a system that has had CQRS applied is that there are TWO models. There is a model representing the mental model of the user and there is another model representing how transactions flow through the system. These two models are often eventually consistent with each other.
The model on the read side, supporting the views is read only. The model supporting the controllers is write-only. Synchronization is achieved either through a shared data model or through events from the write model to the read model.

 

CQRS is pretty much MVC. I am not sure I would assert that it is MVC given the definition but it is very similar. I also doubt that it is Udi or I who first thought of doing it. My guess is you can find many systems doing it.

 

CQRS is also very similar to P-7: INPUT/OUTPUT SEPARATION in http://heim.ifi.uio.no/~trygver/2003/javazone-jaoo/MVC_pattern.pdf 

The input and output aspects of the Editor are technically very different with few interdependencies. Their

combination in a single object tends to make this object unnecessarily complex.

 

The major difference being the separation is only being applied at the first level then returning to a single model as drawn (CQRS is about driving this separation further and further back with benefits at each step). I am rather certain that Trygve has also come across the point that very often the model representing the user's mental model is often very different than the model for expressing how invariants are maintained and that it can be advantageous to push the separation even further back to the models. The benefit is also seen technically when pushing even further back to data storage mechanisms. 

 

Understanding this will take you a long way towards understanding what people are talking about with CQRS it is certainly a variant of if not actually MVC.

 

 

If you are from Australia they are trying to get me to come down. Could you fill out this?