cqrs: theory
DESCRIPTION
This slide explains from from where CQRS comes from. It talks about distributed system and its fallacies and takes a look on CAP theorem.TRANSCRIPT
![Page 1: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/1.jpg)
CQRS : Theory
Shah Ali Newaj Topu(Based on PluralSight)
![Page 2: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/2.jpg)
Distributed System
Shared Data
Write Read
![Page 3: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/3.jpg)
CAP Theorem
2000
Eric Brewer
Symposium on Principles of Distributed Computing
![Page 4: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/4.jpg)
Guarantee
● Consistency
● Availability
● Partition Tolerance
![Page 5: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/5.jpg)
Consistency
![Page 6: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/6.jpg)
Availability
![Page 7: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/7.jpg)
Partition Tolerance
![Page 8: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/8.jpg)
Proof of CAP Theorem
![Page 9: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/9.jpg)
Fallacies of Distributed Computing
● The network is reliable.● Latency is zero.● Bandwidth is infinite.● The network is secure.● Topology doesn't change.● There is one administrator.● Transport cost is zero.● The network is homogeneous.
![Page 10: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/10.jpg)
Fallacies of Distributed Computing
L. Peter Deutsch2000
Network Programming!=Object Oriented Programming
![Page 11: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/11.jpg)
Network Is Reliable
● Some tools hide the network behind proxies.● Method calls are reliable
○ Parameters will be sent○ Return Values will be received○ Exceptions will be caught
● Network calls are not reliable ○ Request may fail○ Response may fail○ Exception could be business logic or Transport
● Code for Failure○ Client cannot tell which side failed○ Indeterminate state.
● Related to Partition Tollerance of CAP Theorem
![Page 12: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/12.jpg)
Latency is Zero
● Method calls take no time.● Requests take time● State of Limbo● Timeouts● Choreograph 2 Machines● Works fine on localhost
![Page 13: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/13.jpg)
Bandwidth is Infinite
● Parameter Passing always works● Shared Memory● No Shared Memory on network● Copy Entire Parameter into one Request● Break parameter into Chunks● Each Chunks has latency● Balance Latency and Bandwidth
![Page 14: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/14.jpg)
Cap Theorem Falacies
Consistency Availability
Partition Tolerance
The network is reliable.
Latency is zero.Bandwidth is infinite.
The network is secure.Topology doesn't change.There is one administrator.
Transport cost is zero.
The network is homogeneous.
Choice
![Page 15: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/15.jpg)
Choice
Stale Data : Forfit ConsistencyReturns Error: Forfits Availability
![Page 16: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/16.jpg)
Patterns
CQRSEvent SourcingDomain Driven DesignEvent Driven Architecture
![Page 17: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/17.jpg)
Domain Driven Design
Eric Evans, 2006
![Page 18: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/18.jpg)
Premies
● The problem domain should inform the software not conform.
● Solution Centric Design○ Data Oriented Model○ CRUD operation ○ Do not relate to the business process
![Page 19: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/19.jpg)
Core Concepts
● Ubiquitous Language● Bounded Contexts● Aggregate Roots
![Page 20: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/20.jpg)
Ubiquitous Language
Language between Business owner and software developers.Takes timeUsed in codeModel Captures understandingNo TranslationNo Assumptions
![Page 21: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/21.jpg)
Collaborative Domain
When you have● Large set of people ● Working with small set of Data
● Locking the Data is necessary● Blocking the user is not.
![Page 22: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/22.jpg)
Bounded Context
● Assigns a specific semantic meaning● Dialect of the ubiquitous language● Optimize to solve a specific problem
![Page 23: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/23.jpg)
Related to CAP Theorem
● Enterprise Data Model○ Cluster of Nodes○ Consistency over availablity○ Single Provider○ Scale up rather scaling out
● Bounded Context○ Smaller cluster of Nodes○ Not reliant upon connection○ Availability over Consistency○ Separate providers
● Requires planning and Patterns.
![Page 24: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/24.jpg)
CQRS
● A Pattern○ Not an Architecture○ Not an Architectural style○ Not a principal
● Command Query Responsibility Segregation.
Udi Dahan Greg Young
![Page 25: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/25.jpg)
CQRS
● Based on Command Query Separation● Applied in VERY Specific Scenario.
![Page 26: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/26.jpg)
Command Query Separation
● A method should either change the state of an object or return a result but not both.
● Gather information● Decide● Change
Command Query
Method that change state Method that return result
Return void Return a type
![Page 27: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/27.jpg)
CQRS
CQRS helps to
Blocking the user when
locking the data
![Page 28: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/28.jpg)
Collaborative Domain
ExampleAirlines seats booking
![Page 29: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/29.jpg)
CQRS
● No immediate Feedback● Do not use every where● Only for collaborative domain
○ Large number of people○ Small number of Data
![Page 30: CQRS: Theory](https://reader034.vdocuments.site/reader034/viewer/2022052307/5598e3fe1a28abbe7d8b471c/html5/thumbnails/30.jpg)
End