by danielovichdk · 7y ago · 0 comments
Given a query a system returns some relatively useful model back.
Honestly, why is this so interesting ?
Sure, you might want to add some autonomous component(s) that manipulate data before returning them.
A good example of applying CQRS to a small part of a system is e.g
1. Data is constantly being written (commands) into the system, excessively. 2. You want to present a "snapshot" of the data, because trying to do it "realtime" for all your users will demand too many resources, and your system will come to a hault. 3. You create the "snapshot" every 10 seconds, from code in an autonomous component, and then store it as a serialized object in a data store. Like a cache sort of. 4. When the query asks the system, the system loads up the "snapshot", deserialze it, and returns that.
Here you have two independent read and write systems. That's CQRS for you.
Do not apply this pattern with a loose hand.
1. There are 2 event handlers for "writes". One handler writes normalized data in a PostgreSQL DB. The other handler writes denormalized data into Firestore. 2. Our frontend uses Firestore so mutations are reflected realtime in the frontend. We never found a need for the command to return data. There is also no need for complex queries in Firestore since our data is denormalized and optimized for reads. 3. The PostgreSQL DB is useful for reporting and complex queries. Our frontend app displays this data only in the reports area.
So far, I don't see how things can get confusing with this pattern.
It's in fact a very simple pattern. But I wouldn't use it system wide because not everything has to be eventuel consitent.
You are describing CQS (Command Query Separation), a la Bertrand Meyer, rather than CQRS. The only thing that CQRS says is that the read and write paths are different. It does not preclude a command from returning a response - or for that matter being handled synchronously.
Why especially this pattern ?
I would say you shouldn't apply any pattern with a loose hand...
CQRS is not a system wide pattern. It should applied in small contexts and corners of domains.
I don't agree that every design pattern has the same level of impact on a system. By far IMHO.