Blog > Design Patterns
Command Query Responsibility Segregation is an important architectural pattern that you should be aware of as a developer. It has many advantages to some of the most difficult problems when building complex and large scale applications.
However, this type of architecture is specially tuned to solve a very specific subset of problems. This adds considerable complexity to your application.
CQRS separates reading and writing into two different models. This means that every method should either be a Command that performs an action or a Query that returns data. A Command cannot return data and a Query cannot change the data.
The main principle behind CQRS is that you use two different models for reading and writing. However, the actual implementation of this idea can be handled in a number of different ways.
Firstly you might use two different models that talk to the same database. When a user issues a Command, the write model will update the database and then the read model will query the database to present the data to the User Interface. This is a good solution for applications that require synchronous processing and immediate results.
When should you use Command Query Responsibility Segregation?
Adding unnecessary complexity to a web application can be the kiss of death. You should always aim to write the simplest solution rather than go nuts for architecture just for the sake of it.
However, for certain types of web applications, I’m sure Command Query Responsibility Segregation would be the answer you are looking for.
Applications that are appropriate for CQRS will typically have many of the same characteristics.
For example, they will require a task-based UI, complex data processing, an imbalance in reads and writes, and eventual consistency would not be a problem.
We should consider implementing CQRS only in certain cases:
- We have changed business requirements a lot
- The business doesn’t know exactly where it’s heading
- We have scalability issues
- We collaborate with other teams (ie: other bounded contexts)
- Multiple services compete to alter the same resources
- We are orchestrating other services around us
- What’s going on in our domain will affect them or vice-versa
- Our domain is write-oriented, we don’t read our own data, other applications do
It’s always good to know about different approaches and common methods to solve difficult problems. One day you might face a situation where CQRS would be the perfect solution.
- .Net Core (3)
- 3D Printing (1)
- Agile Methodologies (1)
- amazon web services (1)
- Angular (2)
- Artificial Intelligence (3)
- Blockchain (1)
- Business Analysis (1)
- Chatbot (1)
- Design Patterns (1)
- Digital Health (6)
- Embedded Systems (1)
- Flutter (1)
- Frontend Development (1)
- Healthcare (3)
- Human Resources in Amatis (1)
- Message Broker (1)
- Nanotechnology (1)
- Neuralink (1)
- php (1)
- Predictive Analytics (1)
- Project Management (1)
- Real-world data (1)
- Robot (1)
- SaaS (1)
- Smart Wearables (2)
- Telehealth (1)
- Test Automation (1)
- Test Driven Development (1)
- UI/UX Design (1)
- Virtual Reality and Augmented Reality (1)
- Vue (1)
- Vuex (1)
- Work Experience (1)