• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
From DDD to CQRS
 

From DDD to CQRS

on

  • 883 views

Presented at dnug-bern.ch on May 19th, 2013 by Dennis Traub

Presented at dnug-bern.ch on May 19th, 2013 by Dennis Traub

Statistics

Views

Total Views
883
Views on SlideShare
883
Embed Views
0

Actions

Likes
7
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    From DDD to CQRS From DDD to CQRS Presentation Transcript

    • From DDD to CQRS presented by Dennis Traub .NET Usergroup Bern - 19. März 2013Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Who‘s that guy? Dennis Traub Founder, Owner, CEO, Single Employee of D. Traub Software Development Consultancy Consultant, developer, trainer, speaker 39 years old Married, father of one 20+ years in software development Hire me at mail@dennistraub.de @dtraubDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Break Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • The „Blue Book“ by Eric Evans Image PlaceholderDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain-Driven Design Domain Service Value Object Aggregate Specification The well- known Reposit ory Patterns Entity Factory And so on . .Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain-Driven Design Ubiquit ous Language Core Domain Domain Expert Bounded Context The important Domain Model Patterns (Generic) Subdomains Context Map And so on . .Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • don‘t build one big model that works for everyoneDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • the tactical Building Blocks we don‘t use DDD when there is no value in formalizing the problemDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • we only use DDD in parts where we get a competitive advantageDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • we focus our effort and resources on the most important subdomainDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • a.k.a. The Core DomainDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Presentation Layer Application Services Domain / Business Model / BLL DAL / O/R-MapperDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Pros of the „Best Practice Architecture“ 1 Easy to build 2 Accepted by management 3 Well-know throughall all seniority levels 4 We know ist limitiationsDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Cons of the „Best Practice Architecture“ 1 Limited scalability 2 Loss of intent 3 Lazy loading, locking, race conditions, … 4 Few classes do way too much stuffDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • And: If the model is basically CRUD where does Business Logic live?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Model Responsibilities 1 Business Logic 6 Aggregation 2 Validation 7 Presentation 3 Structure 8 Persistence 4 Projection 9 Processes 5 Associations 10 Lazy / Eager LoadingDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • the S in SOLIDDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Single Responsibility Principle just because we can doesn‘t mean we shouldDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • why do we try to build One Model to Rule Them All?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • reading and writing are completely different from eachotherDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Sometimes it‘s cheaper to do two things than dealing with the trade-offsDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command Query SeparationDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command Query Separation (CQS) „Every method should either be a command that performs an action or a query that returns data to the caller“ -- Dr. Bertrand MeyerDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command Query Separation (CQS) in other words: Asking a question should not change the answerDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command/Query Responsability SegregationDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • CQS on an Architectural Level Queries Commands Project Details Project List Project Data StoreDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Queries and Projection (Read) Show something Thin Read Layer Data StoreDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Thin Read Layer Concerns: 1 Filtering, Scope 2 Data PresentationDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Thin Read Layer Attributes: 1 Data-Oriented 2 Indexable 3 Can be denormalized and distributed for fast access 4 Only StructureDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Behavior and Modification (Write) Do something Command Handler Domain Model O/R-Mapper Data StoreDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Model Concerns: 1 Business Logic 2 ValidationDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Model Attributes: 1 Normalized 2 Transactional 3 Object-Oriented 4 Persistence Ignorant 5 Only BehaviorDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Commands Refactor Application Service Calls to Objects 1 Serializable 2 Can be enveloped 3 Can be intercepted 4 Can be enriched 5 Communicate intentDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command Handlers Refactored Application Service Methods: 1 Unify interface to all application services 2 Can be wrapped (e.g. Transaction, Authorization, Logging) 3 Can be enveloped (e.g. REST)Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Command Handlers Rule of thumb: One Command Handler per use CaseDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • This is CQRS Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Data StoreDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • BREAKDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain EventDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Event captures the memory of something interesting affecting the domainDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Event the essence is to capture events that trigger a change to the stateDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Event event objects are processed to cause the respective changeDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Domain Event and stored to provide an audit logDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Shopping CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • we don‘t know: What led to this state?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Added to CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Added Added to to Cart CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Added Added Added to to to Cart Cart CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Added Added Added Removed to to to from Cart Cart Cart CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Which model contains more information?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Shopping CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Added Added Added Removed to to to from Cart Cart Cart CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • what if we capture every single event?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • … and reproduce state from this stream of events?Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • An Event Stream … Added Added Added Removed to to to from Cart Cart Cart CartDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • An Event Stream … Added Added Added Removed to to to from Cart Cart Cart Cart Shopping Cart Can be projected into:Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • An Event Stream … Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Shopping Cart … or into this:Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • An Event Stream … Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Audit Trail Shopping Cart … or into this:Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • An Event Stream … Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Audit Trail Shopping Campaign Effectiveness Cart … or into this:Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Data StoreDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer SQL Data Store ViewsDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer INNER JOIN … SQL LEFT OUTER JOIN … Data Store Views UNION … GROUP BY …Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer SELECT * FROM … Table Data Store per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Table Data Store per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Table Data Store per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Event Table Data Store per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Event Event Table Data Store per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Simplified:Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Events Domain Read Model Commands DTOs ClientDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Some CodeDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • if ISBN exists in ShoppingCartDetails Increase Amount else Add New RowDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • if Shopping Cart ID exists in ShoppingCartSummary Increase NumberOfItems Add OfferedPrice to TotalAmount else Add New RowDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • if Amount > 1 ShoppingCartDetails Decrease Amount else Delete RowDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Subtract OfferedPrice to TotalAmount Decrease NumberOfItemsDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • TestabilityDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Write Model Command Handlers Domain ModelDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Write Model Command Handlers Given that certain Events happened Domain ModelDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Write Model When a specific Command is sent Command Handlers Given that certain Events happened Domain ModelDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Write Model When a specific Command is sent Command Handlers Given that certain Events happened Domain Model Event Event Then certain Events (and only those!) should be emittedDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Read Model Thin Read Layer Table per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Read Model Thin Read Layer Given that certain Events happened Table per QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Read Model Thin Read Layer Given that certain Events happened Table per When a specific Event happens QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Testing the Read Model Then each query should return the expected results Thin Read Layer Given that certain Events happened Table per When a specific Event happens QueryDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main ValuesDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main Values additive only we don‘t lose informationDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main Values linearly scalable and distributable Read ModelDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main Values every new view can be created from the beginning of timeDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main Values We can come up with new questions at any timeDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Main Values built-in integration modelDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Proven TechnologyDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • mature business models move away from Update/Delete and become purely transactionalDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • Human resources Medicine Bookkeeping Banking Finances Government …Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • AGENDA DDD Recap CQRS Step by Step the strategic patterns probably simpler than you think! towards CQRS 1 2 3 4 5 6 „Best Practice“ Domain Events End what we call an Architecture are first class citizens Questions & AnswersDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • ? QUESTIONSDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
    • THANK YOU! follow me: @dtraubDennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de