High Performance Distributed Systems with CQRS
-
Upload
jonathan-oliver -
Category
Documents
-
view
3.173 -
download
3
description
Transcript of High Performance Distributed Systems with CQRS
![Page 1: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/1.jpg)
High-Performance Distributed Systems with
Command/Query Responsibility Segregation
Jonathan Oliver Utah Code Camp 2010
![Page 2: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/2.jpg)
Think Differentlier
Best practices != best thinking Blind vs intentional application Question everything How much does it cost?
![Page 3: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/3.jpg)
Domain Muddling and Modeling
What was the original intent? Screen-based aggregate roots? Show domain state? Validation? Get/set, go!
![Page 4: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/4.jpg)
Distributed Systems Architecture
![Page 5: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/5.jpg)
Optimistic and Pessimistic Stalemate
Collaborative users Current state?
Get data Get data
Update data
Stale data
![Page 6: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/6.jpg)
Layeringitis
Why go through all the layers?
![Page 7: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/7.jpg)
Tiers for Fears
Why transform across the tiers? DTOs: more code, tests,
maintenance, $$$ Pre-transformed?
![Page 8: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/8.jpg)
CQRS: Gotta Keep ‘Em Separated
SOLID, Architectural “S”
![Page 9: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/9.jpg)
Query Query Quite “Contrery”
Showing data Query-only storage KISS, YAGNI If it’s stale anyway
List of Customers---------------------------------------------------------------
(from 10 minutes ago)
![Page 10: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/10.jpg)
All Your Database Are Belong To Us
Screen-based views UnDRY your data—data duplication “Persistent View Model” Storage/database requirements Scaling out
SELECT * FROM Carts WHERE ID = 456;
![Page 11: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/11.jpg)
Queries: Summary
Stale data “Persistent View Model” For queries only One table per view Updated by events Data duplication is good No table relationships No foreign keys
![Page 12: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/12.jpg)
Command & Conquer
Say what? What is a command? Intention revealing
SaveInvoice vs PlaceOrder SaveCustomer vs
MakeCustomerDelinquent
![Page 13: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/13.jpg)
UI Design
Excel-based UIs Task-based UIs
Name Address Phone
Bob 1234 Main St q
Jenny q 867-5309
IT Crowd London, England
0118999 88199 9119725 3
![Page 14: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/14.jpg)
This Time It’s Gonna Be Different
Can we fully trust user decisions?
![Page 15: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/15.jpg)
Commands and Validation Validation
Is the input potentially good? Ranges, lengths, etc
Fail fast Leverage persistent view model Unique emails? Decides if a command should be sent Enables high probability of success
![Page 16: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/16.jpg)
Business Rules
Should we do this? Based upon the current system state
![Page 17: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/17.jpg)
Commands: Summary
Expresses intent Reply is: “Thank you, we’ve received
your input.” Asynchronous Amazon Netflix
![Page 18: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/18.jpg)
Domain Models, Take 2
Commands already validated No relationships for reading Only persists what it needs Behavior: Give discounts to high-
volume customers
![Page 19: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/19.jpg)
The Big Picture
Image courtesy Udi Dahan
![Page 20: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/20.jpg)
The Big Picture: Summary
Simple 2-tier queries Commands express intent Task-based UI captures intent Smaller, more focused pieces
![Page 21: High Performance Distributed Systems with CQRS](https://reader030.fdocuments.us/reader030/viewer/2022020723/5484ad425806b5db588b466a/html5/thumbnails/21.jpg)
Questions?