scalable architecture for the cloud. what???? command query responsibility segregation what is it?...

27
CQRS AND WINDOWS AZURE Scalable Architecture for the Cloud

Upload: marcia-little

Post on 27-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

CQRS AND WINDOWS AZUREScalable Architecture for the Cloud

Page 2: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

What????

Command Query Responsibility Segregation What is it? What kinds of apps is it for? What are the moving parts? What does it buy me? How do I do this on Azure?

Page 3: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

What is it?

An architectural pattern Embracing modern requirements

Self service High scalability Asynchronous processing

Page 4: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Applicability

Multiple simultaneous users Untrained users

We’ll be talking about the web

Page 5: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Applicability

Usage patterns More reads than writes No really, more reads than writes Lots, lots, lots more

Page 6: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Applicability

Asynchronous Processing “Thank you, you will receive a

confirmation email shortly.”

Page 7: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

3-Tier Architecture

UI

Domain

DBR

EA

DW

RIT

E

Page 8: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Is it really symmetric?

Reads Fast Synchronous Idempotent Stale

Writes Slow Asynchronous Stateful Current

Page 9: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Sidebar

Command Query Separation Methods should either:

Query State and return a value Or Execute behavior and return

nothing

Bertrand Meyer

Page 10: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

CQRS Architecture

UI

DOMAIN

DB

Page 11: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

CQRS Architecture

UI

WRITE MODEL

WRITE DB

READ MODEL

READ DB

REA

DW

RIT

E

Q

Page 12: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Read Model / Store

Optimized for Reading Denormalized out the wazoo! Matches UI model requirements No logic – DTO One “table” per screen SELECT * FROM TABLE WHERE … No joins

It’s a cache, not a database!

Page 13: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Write Model / Store

Accepts Commands Executes Business Rules Generates Business Events

Page 14: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Write / Read Side Sync

Processes Domain Events Updates tables in read store

Page 15: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

What’s a Command?

A message Named in the imperative

AddNewUser PublishDocument LaunchMissiles

Task Oriented

Page 16: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Command Processing

UI Validates before sending UI Sends command Write model re-validates Write model processes business rules Write model generates events

Assume commands will succeed most of the time

Page 17: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

What’s an event?

A message Named in the past tense

UserAdded NewDocumentPublished WentBoom

Express Changes in the domain over time

Save the event stream for reprocessing

Page 18: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Event Processing

Receive events as they come out Update read stores

Page 19: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

How is this scalable?

Web Farms Event Processors Read Stores

Harder to scale the write side But we have lots more reads anyway

Page 20: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Other Advantages

External System Integration Events write to external system Commands when external system wants

you to do something You know it works, you’re using it!

Page 21: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Mapping to Azure

Queues Table Store

Event Store Read Stores

Worker role Command processors Event Processors

Web role Front end

Page 22: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Show me some code!

Page 23: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

EVENT SOURCINGA special bonus pattern!

Page 24: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

What is event sourcing?

Model Persistence ORM

We’re generating events anyway Events record changes to the domain

over time So we know every state change

that’s happened anyway

Page 25: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Event Sourcing

Load domain entities by “playing back” domain events

No need for ORM Use snapshots for efficiency

Page 26: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Resources

Udi Dahan http://www.udidahan.com

Greg Young http://codebetter.com/blogs/gregyoung/ http://cqrs.wordpress.com/

Mark Nijhof http://cre8ivethought.com/blog/index http://www.agilification.com/post/CQRS-S

eries-from-Mark-Nijhof.aspx

Page 27: Scalable Architecture for the Cloud. What????  Command Query Responsibility Segregation  What is it?  What kinds of apps is it for?  What are the

Questions?