Command-Query Separation (CQS) is a computer programming principle that states that a method in a program should not _both_ process data *and* query for data. "In other words, _asking a question should not change the answer._" [^wiki]
This principle is related to the [[Principle of Atomicity|Principle of Atomicity]] and [[Separation of Concerns]] in that it seeks to reduce the content of a method or component.
## CQRS
Command Query Responsibility Segregation (CQRS) is an application of CQS to data models, using one model to update data and another to retrieve it. [^fowler]
![[Bliki- CQRS#^179278355]] [^fowler]
## Benefits of CQS
- Encourages the use of a task-based, user-triggered UI where processes are run based on user interactions with the interface.
- Integrates nicely into [[Event-driven architecture|Event-based architecture]] and [[Domain-driven design]]
- Confers performance benefits as an application of [[Distributed computing]]
## Disadvantages of CQS
- Having separate models adds to complexity and effort in upkeep
- Can quickly get out of hand and is only suitable for use on bounded contexts (some components only)
-
## References
[^wiki]: Wikipedia. _Command-query separation_. Accessed in May 2021 from [Wikipedia](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation).
[^fowler]: Fowler, M. (2011). _CQRS_. Accessed in May 2021 from [martinfowler.com](https://martinfowler.com/bliki/CQRS.html#:~:text=CQRS%20stands%20for%20Command%20Query,you%20use%20to%20read%20information.).