CQRS

 


Stack doesn't follow CQS as it both deletes and reads at the same time.

FileExists on left can become stale as file may be deleted after FileExists is called.  Code on right is safer method however it doesn't follow CQS.




Scalability 
Always far more Reads than writes, so the separation allows you to scale both independently.  For instance you could have 1 server for all writes and 10 servers for all reads.


Performance
You can add in customised performance enhancements to the read side such as caching and highly optimised queries.

Simplicity
Rather than have one model that is trying to account for reading and writing, CQRS allows you to have one optimised for the specific task of reading or writing.  Allows you to make different decisions for reads and writes. We've only model that does one thing well.

CQRS solves a lot of problems with CRUD based interface.


How many features are in this UI?

The solution to solve a CRUD based interface is a Task based interface.


Example of an Edit personal info which replaces update








Optional: no need to specify event, command and query if follow above guidelines.






Commands and DTOs solve different problems.


Without DTOs, our API will introduce breaking changes with every change of the domain model or will not be able to properly evolve the domain model because of the constraints imposed by the backward compatibility.   Choosing both commands and DTOs and the mapping between them means the application will be both backward compatible and easy to refactor. 





Ok to implement parts of a pattern that make sense.





Need to return an OK that command has been successful and it is fine to return an ID as this is a type of locator.  No point in over complicating the code just for a principle. 


Classic example of the contradiction between the DRY principle and the principle of loose coupling.  Loose coupling wins in the vast majority of cases other than the simplest of ones.





Comments

Popular posts from this blog

Microservices and Service-Oriented Architecture

Version control and Continuous Integration/Continuous Deployment (CI/CD)

Principles of Clean Code