high performance distributed systems with cqrs

21
High-Performance Distributed Systems with Command/Query Responsibility Segregation Jonathan Oliver Utah Code Camp 2010

Upload: jonathan-oliver

Post on 07-Dec-2014

3.173 views

Category:

Documents


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: High Performance Distributed Systems with CQRS

High-Performance Distributed Systems with

Command/Query Responsibility Segregation

Jonathan Oliver Utah Code Camp 2010

Page 2: High Performance Distributed Systems with CQRS

Think Differentlier

Best practices != best thinking Blind vs intentional application Question everything How much does it cost?

Page 3: High Performance Distributed Systems with CQRS

Domain Muddling and Modeling

What was the original intent? Screen-based aggregate roots? Show domain state? Validation? Get/set, go!

Page 4: High Performance Distributed Systems with CQRS

Distributed Systems Architecture

Page 5: High Performance Distributed Systems with CQRS

Optimistic and Pessimistic Stalemate

Collaborative users Current state?

Get data Get data

Update data

Stale data

Page 6: High Performance Distributed Systems with CQRS

Layeringitis

Why go through all the layers?

Page 7: High Performance Distributed Systems with CQRS

Tiers for Fears

Why transform across the tiers? DTOs: more code, tests,

maintenance, $$$ Pre-transformed?

Page 8: High Performance Distributed Systems with CQRS

CQRS: Gotta Keep ‘Em Separated

SOLID, Architectural “S”

Page 9: High Performance Distributed Systems with CQRS

Query Query Quite “Contrery”

Showing data Query-only storage KISS, YAGNI If it’s stale anyway

List of Customers---------------------------------------------------------------

(from 10 minutes ago)

Page 10: High Performance Distributed Systems with CQRS

All Your Database Are Belong To Us

Screen-based views UnDRY your data—data duplication “Persistent View Model” Storage/database requirements Scaling out

SELECT * FROM Carts WHERE ID = 456;

Page 11: High Performance Distributed Systems with CQRS

Queries: Summary

Stale data “Persistent View Model” For queries only One table per view Updated by events Data duplication is good No table relationships No foreign keys

Page 12: High Performance Distributed Systems with CQRS

Command & Conquer

Say what? What is a command? Intention revealing

SaveInvoice vs PlaceOrder SaveCustomer vs

MakeCustomerDelinquent

Page 13: High Performance Distributed Systems with CQRS

UI Design

Excel-based UIs Task-based UIs

Name Address Phone

Bob 1234 Main St q

Jenny q 867-5309

IT Crowd London, England

0118999 88199 9119725 3

Page 14: High Performance Distributed Systems with CQRS

This Time It’s Gonna Be Different

Can we fully trust user decisions?

Page 15: High Performance Distributed Systems with CQRS

Commands and Validation Validation

Is the input potentially good? Ranges, lengths, etc

Fail fast Leverage persistent view model Unique emails? Decides if a command should be sent Enables high probability of success

Page 16: High Performance Distributed Systems with CQRS

Business Rules

Should we do this? Based upon the current system state

Page 17: High Performance Distributed Systems with CQRS

Commands: Summary

Expresses intent Reply is: “Thank you, we’ve received

your input.” Asynchronous Amazon Netflix

Page 18: High Performance Distributed Systems with CQRS

Domain Models, Take 2

Commands already validated No relationships for reading Only persists what it needs Behavior: Give discounts to high-

volume customers

Page 19: High Performance Distributed Systems with CQRS

The Big Picture

Image courtesy Udi Dahan

Page 20: High Performance Distributed Systems with CQRS

The Big Picture: Summary

Simple 2-tier queries Commands express intent Task-based UI captures intent Smaller, more focused pieces

Page 21: High Performance Distributed Systems with CQRS

Questions?