Command Query Responsibility Segregation - CQRS
- Separate code for
- Commands data (Writing)
- Querying data (Reading)
- Message based via Queues.
- Eventual data consistency.
The pattern was originally described by Greg Young in 2011, but promoted by Martin Folwer via his pattern and practices books. Its used in combination with Domain Driven Design and Event programming. The query side of the equation is designed for speed and often includes readonly sources or memory/cached versions of data that eventually become consistent. The Actor Model, defined in 1973 by Karl Hewitt, was added as the complimentary architecture by Vaughn Vernon.
Messages sent to queues are asynchronous, providing very fast processing of data changes.
- Pro-Active software architecture requires actively monitoring data state.
- Reactive software architecture, subscribes to state changes via Message events. Desirable feature.
Not core features of CQRS
- Resiliency - implementation strategy to resolve.
- Elastic scaling up and down to meet demand is also part of the implementation strategy.
The pattern is just a guide, the implementation of CQRS is left up to the software engineer. It fits into a micro-services architecture and provides excellent starting points for Service Reliability Engineering.
References
Eventual Consistency Trade-Offs in Distributed Systems
Consistent, Available, Tolerant - CAP Theorem
Event Storming - ‘What happened’
DevOps - Service Reliability Engineering
Akka.net - Actor Model framework