scalable architecture for the cloud. what???? command query responsibility segregation what is it?...
TRANSCRIPT
![Page 1: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/1.jpg)
CQRS AND WINDOWS AZUREScalable Architecture for the Cloud
![Page 2: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/2.jpg)
What????
Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the moving parts? What does it buy me? How do I do this on Azure?
![Page 3: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/3.jpg)
What is it?
An architectural pattern Embracing modern requirements
Self service High scalability Asynchronous processing
![Page 4: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/4.jpg)
Applicability
Multiple simultaneous users Untrained users
We’ll be talking about the web
![Page 5: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/5.jpg)
Applicability
Usage patterns More reads than writes No really, more reads than writes Lots, lots, lots more
![Page 6: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/6.jpg)
Applicability
Asynchronous Processing “Thank you, you will receive a
confirmation email shortly.”
![Page 7: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/7.jpg)
3-Tier Architecture
UI
Domain
DBR
EA
DW
RIT
E
![Page 8: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/8.jpg)
Is it really symmetric?
Reads Fast Synchronous Idempotent Stale
Writes Slow Asynchronous Stateful Current
![Page 9: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/9.jpg)
Sidebar
Command Query Separation Methods should either:
Query State and return a value Or Execute behavior and return
nothing
Bertrand Meyer
![Page 10: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/10.jpg)
CQRS Architecture
UI
DOMAIN
DB
![Page 11: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/11.jpg)
CQRS Architecture
UI
WRITE MODEL
WRITE DB
READ MODEL
READ DB
REA
DW
RIT
E
Q
![Page 12: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/12.jpg)
Read Model / Store
Optimized for Reading Denormalized out the wazoo! Matches UI model requirements No logic – DTO One “table” per screen SELECT * FROM TABLE WHERE … No joins
It’s a cache, not a database!
![Page 13: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/13.jpg)
Write Model / Store
Accepts Commands Executes Business Rules Generates Business Events
![Page 14: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/14.jpg)
Write / Read Side Sync
Processes Domain Events Updates tables in read store
![Page 15: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/15.jpg)
What’s a Command?
A message Named in the imperative
AddNewUser PublishDocument LaunchMissiles
Task Oriented
![Page 16: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/16.jpg)
Command Processing
UI Validates before sending UI Sends command Write model re-validates Write model processes business rules Write model generates events
Assume commands will succeed most of the time
![Page 17: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/17.jpg)
What’s an event?
A message Named in the past tense
UserAdded NewDocumentPublished WentBoom
Express Changes in the domain over time
Save the event stream for reprocessing
![Page 18: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/18.jpg)
Event Processing
Receive events as they come out Update read stores
![Page 19: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/19.jpg)
How is this scalable?
Web Farms Event Processors Read Stores
Harder to scale the write side But we have lots more reads anyway
![Page 20: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/20.jpg)
Other Advantages
External System Integration Events write to external system Commands when external system wants
you to do something You know it works, you’re using it!
![Page 21: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/21.jpg)
Mapping to Azure
Queues Table Store
Event Store Read Stores
Worker role Command processors Event Processors
Web role Front end
![Page 22: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/22.jpg)
Show me some code!
![Page 23: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/23.jpg)
EVENT SOURCINGA special bonus pattern!
![Page 24: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/24.jpg)
What is event sourcing?
Model Persistence ORM
We’re generating events anyway Events record changes to the domain
over time So we know every state change
that’s happened anyway
![Page 25: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/25.jpg)
Event Sourcing
Load domain entities by “playing back” domain events
No need for ORM Use snapshots for efficiency
![Page 26: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/26.jpg)
Resources
Udi Dahan http://www.udidahan.com
Greg Young http://codebetter.com/blogs/gregyoung/ http://cqrs.wordpress.com/
Mark Nijhof http://cre8ivethought.com/blog/index http://www.agilification.com/post/CQRS-S
eries-from-Mark-Nijhof.aspx
![Page 27: Scalable Architecture for the Cloud. What???? Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649e455503460f94b393d7/html5/thumbnails/27.jpg)
Questions?