IntroductionCQRSPieter Joost van de Sande
Thank you VSOFT!!
AgendaHow we do things now
What CQRS changes to that
Building a CQRS architecture
Some demo stuff
Discussion
Beer!TypicalarchitecturesYou should recognize this
Typical architectures
Typical architecturesPresentationDomainData
N-LayerFlexible – we could replace a layer without breaking much.
Simple separation that is easy to explain.
Higher abstraction with each layer.
Known by a lot of people.
Supportedby tools andframeworks
Lots of resources availableWhat the n-tier tunnel brought us
Typical architectures
TWO fundamental thingsEvery system has this
data
Transitions
What is CQRS?COMMANDQUERYRESPONSIBILITYSEGREGATION
Cqrs ConceptMove from N-layer to…
N-LAYERarchitecturePresentationDomainData
PresentationDomainData
PresentationDomainData
PresentationDomainData
PresentationReadState transitionsDomainData
fromCQRS ConcepttoarchitectureThis adds more value!
User interface
Demand for dataBecause we have some screens to fill
WE read a lot
WE have multiple screens to fill
Data should be close to us
Demandfor dataUser interface has different views tofill.
It shouldnot have toexecute business rules on the data.
It requests data manytimes.
It shouldbe close tous.
Getting data shouldbesimple (select * from x where y)Examples:Get all products of user XGet total price of all orders of month May
User interface
Read sideUser interface
Read sideRead databasesUser interface
Read sideRead databasesqueryUser interface
Read sideThe only need it has to serve is reading.Do we need an relational data here?
Contains the data in an form we need
Facades should be minimized
Read models do not have to be on one location...
They should be close to the clientRead sideRead databasesqueryUser interface
Demand for changeOtherwise things are static
I want to tell the system somethingPlease move customer X to this new address
Change has intentUsers don’t make changes for nothing.This intent has value!Correct the address for user XCustomer X moved to new addressVS.
Multiple stepsUsers can take multiple steps before they reach the end goal. These steps can be very useful to us.
CommandsModel that is optimized the describe changes.
Commands contain all the data needed to execute the underlying action.
Contain the intent of the change.Examples:AddProductToShoppingCartPurchaseOrderMoveUserToNewAddressCorrectAddressForUser
Read sideRead databasesqueryUser interface
Read sideWrite sideRead databasesqueryUser interface
Read sideWrite sideRead databasesCommandhandlerscommandsqueryUser interface
Read sideWrite sideRead databasesFacadeDomainCommandhandlerscommandsDTO’sUser interface
Greg Young:“State transitions are an important part of our problem space and should be modeled within our domain.”
The ‘old’ domain model
Domain focused on behavior

Introduction to CQRS