Top Banner
CQRS : Theory Shah Ali Newaj Topu (Based on PluralSight)
30

CQRS: Theory

Jul 05, 2015

Download

Technology

This slide explains from from where CQRS comes from. It talks about distributed system and its fallacies and takes a look on CAP theorem.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CQRS: Theory

CQRS : Theory

Shah Ali Newaj Topu(Based on PluralSight)

Page 2: CQRS: Theory

Distributed System

Shared Data

Write Read

Page 3: CQRS: Theory

CAP Theorem

2000

Eric Brewer

Symposium on Principles of Distributed Computing

Page 4: CQRS: Theory

Guarantee

● Consistency

● Availability

● Partition Tolerance

Page 5: CQRS: Theory

Consistency

Page 6: CQRS: Theory

Availability

Page 7: CQRS: Theory

Partition Tolerance

Page 8: CQRS: Theory

Proof of CAP Theorem

Page 9: CQRS: Theory

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

Fallacies of Distributed Computing

L. Peter Deutsch2000

Network Programming!=Object Oriented Programming

Page 11: CQRS: Theory

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

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

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

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

Choice

Stale Data : Forfit ConsistencyReturns Error: Forfits Availability

Page 16: CQRS: Theory

Patterns

CQRSEvent SourcingDomain Driven DesignEvent Driven Architecture

Page 17: CQRS: Theory

Domain Driven Design

Eric Evans, 2006

Page 18: CQRS: Theory

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

Core Concepts

● Ubiquitous Language● Bounded Contexts● Aggregate Roots

Page 20: CQRS: Theory

Ubiquitous Language

Language between Business owner and software developers.Takes timeUsed in codeModel Captures understandingNo TranslationNo Assumptions

Page 21: CQRS: Theory

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

Bounded Context

● Assigns a specific semantic meaning● Dialect of the ubiquitous language● Optimize to solve a specific problem

Page 23: CQRS: Theory

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

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

CQRS

● Based on Command Query Separation● Applied in VERY Specific Scenario.

Page 26: CQRS: Theory

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

CQRS

CQRS helps to

Blocking the user when

locking the data

Page 28: CQRS: Theory

Collaborative Domain

ExampleAirlines seats booking

Page 29: CQRS: Theory

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

End