+ All Categories
Home > Documents > CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS &...

CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS &...

Date post: 23-Jun-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
47
CQRS at Enterprise Scale Graham Brooks Coding Architect @grahamcbrooks [email protected] grahambrooks.com/talks
Transcript
Page 1: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

CQRS at Enterprise ScaleGraham Brooks Coding Architect

! @grahamcbrooks

" [email protected]

# grahambrooks.com/talks

Page 2: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest

Page 3: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Simple Object Access Protocol

Page 4: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest

Page 5: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest( Web App

SOAP

Page 6: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

<definitions name="EndorsementSearch" targetNamespace="http://namespaces.snowboard-info.com" xmlns:es="http://www.snowboard-info.com/EndorsementSearch.wsdl" xmlns:esxsd="http://schemas.snowboard-info.com/EndorsementSearch.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" >

<!-- omitted types section with content model schema info -->

<message name="GetEndorsingBoarderRequest"> <part name="body" element="esxsd:GetEndorsingBoarder"/> </message>

<message name="GetEndorsingBoarderResponse"> <part name="body" element="esxsd:GetEndorsingBoarderResponse"/> </message>

<portType name="GetEndorsingBoarderPortType"> <operation name="GetEndorsingBoarder"> <input message="es:GetEndorsingBoarderRequest"/> <output message="es:GetEndorsingBoarderResponse"/> <fault message="es:GetEndorsingBoarderFault"/> </operation> </portType>

<binding name="EndorsementSearchSoapBinding" type="es:GetEndorsingBoarderPortType"> <soap:binding style="document"

source w3c.org

Page 7: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

SOAP

• XML based

• Intolerant to change versioning is particularly difficult

• Middleware not (web) client facing

• Its XML based

Page 8: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

REpresentational State Transfer

Page 9: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest( Web App

SOAP

Page 10: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest

GETPOST/PUT/DELETE

Page 11: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

REST• Uniform Interface Client–server

• Stateless

• Cacheable

• Layered system

• Identification of resources

• Manipulation of resources through these representations

• Self-descriptive messages

• Hypermedia as the engine of application state (HATEOAS)

Page 12: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Command Query Responsibility Segregation

Page 13: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Responsibility Segregation

Page 14: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest

GETPOST/PUT/DELETE

Page 15: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

ResponseRequest

Resp

onsib

ility

Segr

egat

ion

Page 16: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

Store

' Business Logic

Command

Page 17: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Commands• What makes a good command?

• RESTful? - POST/PUT/DELETE

• SOAP - set()

• Something else

• POST /customers/123/addresses { "command": "change-address", "reason": "moved", "address": {...} }

$ Client

% Server

Store

' Business Logic

Command

Page 18: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

$ Client

% Server

View Store

' View

Query

Page 19: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

View Store

' View

Query

$ Client

% Server

Store

' Business Logic

Command

Resp

onsi

bilit

y Se

greg

atio

n

Page 20: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

View Store

' View

Query

$ Client

Store

' Business Logic

Command

Resp

onsi

bilit

y Se

greg

atio

n

Page 21: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

Store

' View

Query

$ Client

Store

' Business Logic

Command

Resp

onsi

bilit

y Se

greg

atio

n

Domain models and view models stored separately

Different interaction ) Different Technologies

Page 22: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

Store

' View

Query

$ Client

Store

' Business Logic

Command

Message Bus

Page 23: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

Store

' View

Query

$ Client

* Event Store

' Business Logic

Command

Message Bus

Page 24: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

Store

' View

Query

$ Client

* Event Store

' Business Logic

Command

Message Bus

Scaling reflects load - Read/Update ratio 10:1

Technology reflects use SQL/NoSQL

Page 25: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

% Server

Store

' View

Query

$ Client

* Event Store

' Business Logic

Command

Message Bus

!!Disconnect!!

Real-time ) Synchronous

CQRS is inherently asynchronous

Page 26: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

CQRS & the Enterprise

Page 27: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Scale

Page 28: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Query

$ Client

Command

Message Bus

+,

+++

Customer Cluster

+,

+++

Account Cluster

"

"

-

. . .

/

Page 29: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Query

$ Client

Command

Message Bus

+,

+++

Customer Cluster

+,

+++

Account Cluster

Page 30: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Message Bus

+,

+++

+,

+++

Page 31: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Message Bus

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

Page 32: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

Page 33: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++

+,

+++ 0

0

0

0

0

0

0 0

Consistency Latency 0+0+0

Page 34: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

ResilienceEach Service is independent because it contains all the data needed to complete

or accept a command from the user.

Page 35: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

CouplingServices communicate the results of an action. Services are only coupled by the

data and not for processing.

Page 36: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

' Business Logic

60s Event Sourcing

Store

1 Command: Change Address

1 Command: New Customer

2 Event: NewCustomerEvent

1 Command: Name Change

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Page 37: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

60s Event Sourcing

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Page 38: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Replay

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Complaints

Store

Page 39: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Replay - endstate

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Complaints

Store

2 Complaints Customer V3

Page 40: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Replay

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Complaints

Store

Page 41: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Store

Replay

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Complaints

2 Customer Record V12 Customer Record V22 Customer Record V3

Page 42: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Replay - endstate

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Customer Orders

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

2 Customer Record V12 Customer Record V22 Customer Record V3

Complaints

Store

2 Complaints Customer V3

Page 43: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Replay Challenges• Scale: How do you replay billions of

events

• Snapshotting can help but event volume >= aggregate count

• Event processing must be idempotent.

• Compound problem with fan in - service requires events from many others.

Store

2 Event: NewCustomerEvent

2 Event: AddressChangedEvent

2 Event: NameChangedEvent

Page 44: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Highlights• Captures Intent - Customer Moved - change address

• Encourages DDD and Event Sourcing

• Handles complexity well

• Distinct Command and View model(s)

• Becoming Popular

• Extremely scaleable!

• Very decoupled

Page 45: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Lowlights

Complex

Deceptively complex

Relatively new

Immature framework support

Not good for simple domains

Page 46: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Axon

http://www.axonframework.org

Page 47: CQRS at Enterprise Scale - Graham Brooks · 2019-03-24 · CQRS is inherently asynchronous. CQRS & the Enterprise. Scale. Query $ Client Command Message Bus ... CQRS at Enterprise

Thank YouGraham Brooks

! @grahamcbrooks

" [email protected]

# grahambrooks.com/talks


Recommended