+ All Categories
Home > Technology > Introduction to CQRS and DDDD

Introduction to CQRS and DDDD

Date post: 14-Dec-2014
Category:
Upload: vladik-khononov
View: 234 times
Download: 1 times
Share this document with a friend
Description:
 
Popular Tags:
30
Transcript
Page 1: Introduction to CQRS and DDDD
Page 2: Introduction to CQRS and DDDD

EXORCISM“THE PRACTICE OF EVICTING DEMONS OR OTHER SPIRITUAL ENTITIES FROM A PERSON OR AN AREA THEY ARE BELIEVED TO HAVE POSSESSED”

Page 3: Introduction to CQRS and DDDD

CQRSDISTRIBUTED DOMAIN DRIVEN DESIGN

Page 4: Introduction to CQRS and DDDD

Classic ArchitectureClient executes interactors

Interactor modifies data and returns ViewModel

Page 5: Introduction to CQRS and DDDD

Step 1: CQSCommand/Query segregation

Commands - write data, void

Queries - read data

Page 6: Introduction to CQRS and DDDD

Step 1: CQSpublic class SubmitAction : Interactor{

public ShowLeadViewModel Execute(LeadActionDTO action){

var lead = ExecuteLeadAction(action); var viewModel = BuildViewModel(lead);

return viewModel;}

}

Page 7: Introduction to CQRS and DDDD

Step 1: CQSpublic class SubmitAction : Interactor{

public void Execute(LeadActionDTO action){

ExecuteLeadAction(action);}

public ShowLeadViewModel GetLeadInfo(long id){

var lead = GetLead(id); var viewModel = BuildViewModel(lead);

return viewModel;}

}

Page 8: Introduction to CQRS and DDDD

Step 1: CQSpublic class SubmitAction : Interactor{

public void Execute(LeadActionDTO action){

ExecuteLeadAction(action);}

public ShowLeadViewModel GetLeadInfo(long id){

return GetLeadViewModel(id);}

}

Page 9: Introduction to CQRS and DDDD

Step 1: CQS

Separated Query/Command logic

Commands are executed asynchronously

Queries are executed though a thin read layer

Page 10: Introduction to CQRS and DDDD

Normalization: 3NF vs. 1NF

lead_id status_id queue_idcontact_i

dcampaign_id

assigned_to_id

1043 1 2 241734 54 108

1044 3 5 241771 78 109

lead_id status queuecontact_name

campaignassigned_to

1043 New WaitYau

SiongSaraya

[03SEP2012]Alex

Delors

1043Contacte

dConverte

dDimas

WijayaGunggo_

CA [060512]Mona

Barbara

Page 11: Introduction to CQRS and DDDD

Step 2

Write model: 3NF

Read model: 1NF

Page 12: Introduction to CQRS and DDDD

Step 2

Page 13: Introduction to CQRS and DDDD

Step 2: Events

Page 14: Introduction to CQRS and DDDD

Step 2: Events

Multiple projections

Scalable reads

Decoupled storage mechanism

RDMBS, Document store, Key/Value store, plain files (local or S3), Sharepoint List, Lucene, Cloud Search

No need for NHibernate Profiler licenses

Page 15: Introduction to CQRS and DDDD

Step 2: Events

Page 16: Introduction to CQRS and DDDD

No reliable source of truth.

Page 17: Introduction to CQRS and DDDD

Step 3

Page 18: Introduction to CQRS and DDDD

Step 3: Events History

Page 19: Introduction to CQRS and DDDD

Step 3: Events History

Every data change is logged

Reliable source of truth

Read model can be regenerated anytime

Write model can be regenerated anytime

Page 20: Introduction to CQRS and DDDD

Step 3: Events History

Page 21: Introduction to CQRS and DDDD

Writes are not scalable.

Page 22: Introduction to CQRS and DDDD

Step 4

Page 23: Introduction to CQRS and DDDD

Step 4var lead1 = {

“leadId”: 15423,“customer_id”: “[email protected]”,“events”: [

{ “type”: “lead_created”, “data”: {…}, “date”: “20131216T1242” },

{ “type”: “lead_assigned”, “data”: {…}, “date”: “20131216T1342” },

{ “type”: “activity_created”, “data”: {…}, “date”: “20131216T1432” },

{ “type”: “new_lead_event”, “data”: {…}, “date”: “20131216T1522” },

{ “type”: “activity_created”, “data”: {…}, “date”: “20131216T1432” }

]}

Page 24: Introduction to CQRS and DDDD

Step 4

Page 25: Introduction to CQRS and DDDD

Step 4: Event Sourcing

Page 26: Introduction to CQRS and DDDD

Step 4: Event Sourcing

Infinitely scalable reads

Infinitely scalable writes

Audit data

New business insights form past data

Replay events for debugging and analysis

Retroactive logic changes (=bug fixes)

Lightweight backups

NoSQL

No deadlocks

No DBA

CHEAP!!!!!

Page 27: Introduction to CQRS and DDDD

CQRS

Commands

Events

Event Store

ViewModels / Projections

Page 28: Introduction to CQRS and DDDD

Questions?

Page 29: Introduction to CQRS and DDDD

DDD: Building Blocks

Domain Driven Design

Entity

Aggregate

Repository

Page 30: Introduction to CQRS and DDDD

DDD: Aggregate

shoppingCart = {“id”: 1234,“items”: [{

{ “product_id”: 123, “amount”: 1, “price”: 10},{ “product_id”: 123, “amount”: 1, “price”: 10}

}]}


Recommended