+ All Categories
Home > Documents > Think different cqrs

Think different cqrs

Date post: 25-Jun-2015
Category:
Upload: prajeeshprathap
View: 85 times
Download: 1 times
Share this document with a friend
Popular Tags:
41
Command/ Query Responsibility Segregation
Transcript
Page 1: Think different cqrs

Command/ Query Responsibility

Segregation

Page 2: Think different cqrs
Page 3: Think different cqrs

• How we started?• Distributed systems architecture• UI design• Domain model

What are we going to see

Page 4: Think different cqrs

What not

Page 5: Think different cqrs
Page 6: Think different cqrs
Page 7: Think different cqrs

And then came

And with it

Page 8: Think different cqrs

Ultimate source of truth

Page 9: Think different cqrs
Page 10: Think different cqrs

• Paper was gone.• The source of truth changed

And then…

Page 11: Think different cqrs

But

Page 12: Think different cqrs

And

Page 13: Think different cqrs

Distributed Architecture

Page 14: Think different cqrs

Change

Data

Get D

ata

Get Data

User Collaboration

Users looking

into stale data

Page 15: Think different cqrs

Cache

So why all the layers?

Page 16: Think different cqrs

Cache

Relational data to DTO’s using ORMs

Map DTO’s to Domain Objects/ WS

Map from Domain Objects/ WS to View Models

Why transform between layers?

Page 17: Think different cqrs

List of customers------------------------------------------------------------Data corrected as of 10 minutes

Be upfront about it

Page 18: Think different cqrs

Only data, no behavior

No objects so why ORM’s

Page 19: Think different cqrs

Query only

Persistent View Model

For each view in the UI have a table/ view in the DB

KISS

Page 20: Think different cqrs
Page 21: Think different cqrs

Search

• Find what the users want• Separate UI talking to a different store

Page 22: Think different cqrs

No relations between Views/ Tables

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Key

Value

Vs.

Page 23: Think different cqrs

• Data duplication.• Avoid calculations on data.• Deploy to web tier (No need to hop

through firewalls, only SELECT is allowed)• Role-based security not needed.• Use for preliminary validation results in

less command rejection.

Data duplication

Page 24: Think different cqrs

Commands

Page 25: Think different cqrs

Can we fully trust our user decisions?

Page 26: Think different cqrs

• Validations– Is the input potentially good– Structured correctly– Ranges, lengths etc.

• Rules– Should we do this?– Based on the current system state– What the user saw is irrelevant

Validations and Business Rules

Page 27: Think different cqrs

• Easy versioning• Deployment

Autonomous components

Page 28: Think different cqrs

Command Processing tiers

Page 29: Think different cqrs

Capturing user intent

• Differentiating between– Correcting a shipping address – User has moved, rerouting shipment location

• Sometimes users accidently modify fields by tabbing.

Page 30: Think different cqrs

Reservation systems

Page 31: Think different cqrs

Reservation systems

Page 32: Think different cqrs

• Checkbox based UI• Why user’s need bulk booking?• But then concurrency happens• Then book seats somewhere else

Not capturing user intent

Page 33: Think different cqrs

Capturing user intent

• Group reservation• Enter number of people and preferred

seating location• System emails back when reservation is

confirmed

Page 34: Think different cqrs

• On submit from browser, show comment using AJAX on page.

• Why wait for response from server.• Does the user calls all his friends and tell

them about the comment he posted?

Posting a comment on Facebook

Page 35: Think different cqrs

DOMAIN MODEL

Page 36: Think different cqrs

• Validations:– Commands are validated before the domain

model is called• Queries:

– Entity relations for reading are unnecessary

What aren’t they for

Page 37: Think different cqrs

• In addition to doing what the command said, doing other things as well.

What are they for?

Page 38: Think different cqrs

• The domain model is not responsible for persisting all the data. Only persist what is needed.

• The rest of the world is using the data from the query store anyway

Only persist what is needed

Page 39: Think different cqrs

CQRS

Domain

Commands

Queries

PUTTING IT ALL TOGETHER

Page 40: Think different cqrs

For better scalability, add pub/ sub

Page 41: Think different cqrs

Recommended