Chapter 12. Command Query Responsibility Separation (CQRS)
Up to this point in this book, we have worked to put together a simple blog application using the CRUD pattern: Create, Retrieve, Update, and Delete. We have done an excellent job of ensuring services are handling our business logic and our controllers are simply gateways into those services. The controllers take care of validating the request and then pass the request to the service for processing. In a small application like this, CRUD works wonderfully.
But what happens when we are dealing with a large scale application that may have unique and complex business logic for saving data? Or maybe we would like to initiate some logic in the background so the UI is able to call APIs without having to wait for all the business logic to finish. These are areas where CQRS makes sense. CQRS can be used to isolate and break apart complex business logic, initiate that business logic synchronously or asynchronously, and compose the isolated...