Website
OrderService
PlaceOrder(order)
Request Order
Response OrderId
Synchronous
The website is blocked while calling the Order Service
Website
Message Queue
Message: PlaceOrder
Asynchronous
The website is NOT blocked while the place order is processed
Windows Service
Process the PlaceOrder message
Connect
Receive
PlaceOrder
Command and Query Responsibility Segregation
"Command Query Separation" describes the principle that an object's methods should be either commands or queries. A query returns data and does not alter the state of the object; a command changes the state of an object but does not return any data. The benefit is that you have a better understanding what does, and what does not, change the state in your system.
CQRS is simply the creation of two objects where there was previously only one. The separation occurs based upon whether the methods are a command or a query. A command is any method that mutates state and a query is any method that returns a value.
-Greg Young, CQRS, Task Based UIs, Event Sourcing agh!
CustomerService
void MakeCustomerPreferred(CustomerId)
Customer GetCustomer(CustomerId)
CustomerSet GetCustomersWithName(Name)
CustomerSet GetPreferredCustomers()
void ChangeCustomerLocale(CustomerId, NewLocale)
void CreateCustomer(Customer)
void EditCustomerDetails(CustomerDetails)
CustomerWriteService
void MakeCustomerPreferred(CustomerId)
void ChangeCustomerLocale(CustomerId, NewLocale)
void CreateCustomer(Customer)
void EditCustomerDetails(CustomerDetails)
CustomerReadService
Customer GetCustomer(CustomerId)
CustomerSet GetCustomersWithName(Name)
CustomerSet GetPreferredCustomers()
CQRS is a simple pattern that strictly segregates the responsibility of handling command input into an autonomous system from the responsibility of handling side-effect-free query/read access on the same system. Consequently, the decoupling allows for any number of homogeneous or heterogeneous query/read modules to be paired with a command processor.
In simple terms, you don't service queries via the same module of a service that you process commands through. In REST terminology, GET requests wire up to a different thing from what PUT, POST, and DELETE requests wire up to.
—Clemens Vasters (CQRS Advisors Mail List)
idempotent messaging
SAGA