cqrs: theory

Post on 05-Jul-2015

201 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

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

CQRS : Theory

Shah Ali Newaj Topu(Based on PluralSight)

Distributed System

Shared Data

Write Read

CAP Theorem

2000

Eric Brewer

Symposium on Principles of Distributed Computing

Guarantee

● Consistency

● Availability

● Partition Tolerance

Consistency

Availability

Partition Tolerance

Proof of CAP Theorem

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.

Fallacies of Distributed Computing

L. Peter Deutsch2000

Network Programming!=Object Oriented Programming

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

Latency is Zero

● Method calls take no time.● Requests take time● State of Limbo● Timeouts● Choreograph 2 Machines● Works fine on localhost

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

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

Choice

Stale Data : Forfit ConsistencyReturns Error: Forfits Availability

Patterns

CQRSEvent SourcingDomain Driven DesignEvent Driven Architecture

Domain Driven Design

Eric Evans, 2006

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

Core Concepts

● Ubiquitous Language● Bounded Contexts● Aggregate Roots

Ubiquitous Language

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

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.

Bounded Context

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

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.

CQRS

● A Pattern○ Not an Architecture○ Not an Architectural style○ Not a principal

● Command Query Responsibility Segregation.

Udi Dahan Greg Young

CQRS

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

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

CQRS

CQRS helps to

Blocking the user when

locking the data

Collaborative Domain

ExampleAirlines seats booking

CQRS

● No immediate Feedback● Do not use every where● Only for collaborative domain

○ Large number of people○ Small number of Data

End

top related