SlideShare a Scribd company logo
1 of 103
From DDD to CQRS

                presented by Dennis Traub
                             .NET Usergroup Bern - 19. MΓ€rz 2013




Dennis 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




               @dtraub




Dennis 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 & Answers




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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
The β€žBlue Bookβ€œ by Eric Evans




                                          Image Placeholder




Dennis 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 everyone




Dennis 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 problem




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
we only use DDD in parts
                            where we get a competitive
                                        advantage




Dennis Traub – Software Development Consultancy     @dtraub – mail@dennistraub.de
we focus our effort and resources on
                the most             important subdomain




Dennis Traub – Software Development Consultancy    @dtraub – mail@dennistraub.de
a.k.a. The             Core Domain




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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
Presentation Layer


                                      Application Services


                            Domain / Business Model / BLL


                                       DAL / O/R-Mapper




Dennis 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 limitiations




Dennis 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 stuff




Dennis 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 Loading




Dennis Traub – Software Development Consultancy                      @dtraub – mail@dennistraub.de
the S in SOLID




Dennis Traub – Software Development Consultancy        @dtraub – mail@dennistraub.de
Single Responsibility Principle
               just because we can doesnβ€˜t mean we should




Dennis 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 eachother




Dennis Traub – Software Development Consultancy             @dtraub – mail@dennistraub.de
Sometimes itβ€˜s cheaper to do two things
                       than dealing with the trade-offs




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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
Command Query Separation




Dennis 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 Meyer




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
Command Query Separation (CQS)




                                         in other words:
                            Asking a question should
                            not change the answer




Dennis Traub – Software Development Consultancy            @dtraub – mail@dennistraub.de
Command/Query
                   Responsability Segregation




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
CQS on an Architectural Level



                          Queries                                  Commands




         Project Details               Project List                 Project




                                                      Data Store


Dennis Traub – Software Development Consultancy                    @dtraub – mail@dennistraub.de
Queries and Projection (Read)


                                            Show something




                                            Thin Read Layer



                                                  Data Store

Dennis Traub – Software Development Consultancy                @dtraub – mail@dennistraub.de
Thin Read Layer



             Concerns:

             1    Filtering, Scope


             2    Data Presentation




Dennis 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 Structure




Dennis Traub – Software Development Consultancy                @dtraub – mail@dennistraub.de
Behavior and Modification (Write)


                                              Do something



                                          Command Handler


                                                  Domain Model


                                                  O/R-Mapper



                                                  Data Store

Dennis Traub – Software Development Consultancy                  @dtraub – mail@dennistraub.de
Domain Model



             Concerns:

             1    Business Logic


             2    Validation




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Domain Model



             Attributes:

             1    Normalized


             2    Transactional

             3    Object-Oriented


             4    Persistence Ignorant


             5    Only Behavior




Dennis 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 intent




Dennis 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 Case




Dennis 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 Store

Dennis Traub – Software Development Consultancy                       @dtraub – mail@dennistraub.de
BREAK




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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
Domain Event




Dennis Traub – Software Development Consultancy    @dtraub – mail@dennistraub.de
Domain Event




                              captures the memory of
       something interesting affecting the domain




Dennis Traub – Software Development Consultancy        @dtraub – mail@dennistraub.de
Domain Event




                the essence is to capture         events that
                       trigger a change to the state




Dennis Traub – Software Development Consultancy        @dtraub – mail@dennistraub.de
Domain Event




                       event objects are processed to
                        cause the respective change




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Domain Event




                  and stored to provide an        audit log




Dennis Traub – Software Development Consultancy       @dtraub – mail@dennistraub.de
Shopping Cart




Dennis 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
           Cart




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Added                  Added
            to                     to
           Cart                   Cart




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Added                  Added            Added
            to                     to               to
           Cart                   Cart             Cart




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
Added                  Added            Added   Removed
            to                     to               to      from
           Cart                   Cart             Cart     Cart




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
Which model contains more information?




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Shopping Cart




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
Added                  Added            Added   Removed
            to                     to               to      from
           Cart                   Cart             Cart     Cart




Dennis 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     Cart




Dennis 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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
Client


       Commands                                                                 Queries

                    Command Handlers


                     Domain Model

                         O/R Mapper                            Thin Read Layer



                                                  Data Store

Dennis Traub – Software Development Consultancy                       @dtraub – mail@dennistraub.de
Client


       Commands                                                                 Queries

                    Command Handlers


                     Domain Model

                         O/R Mapper                        Thin Read Layer


                                                               SQL
                       Data Store                             Views


Dennis 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
                                                                          Query



Dennis 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
                                                                         Query



Dennis 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
                                                                         Query



Dennis 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
                                                                         Query



Dennis 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
                                                                         Query



Dennis Traub – Software Development Consultancy                   @dtraub – mail@dennistraub.de
Simplified:




Dennis Traub – Software Development Consultancy       @dtraub – mail@dennistraub.de
Events

                             Domain                          Read Model




            Commands                                                 DTOs




                                                    Client




Dennis Traub – Software Development Consultancy                    @dtraub – mail@dennistraub.de
Some Code




Dennis 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 Row




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
if Shopping Cart ID exists in ShoppingCartSummary
          Increase NumberOfItems
          Add OfferedPrice to TotalAmount
      else
          Add New Row




Dennis 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 Row




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Subtract OfferedPrice to TotalAmount
                   Decrease NumberOfItems




Dennis Traub – Software Development Consultancy           @dtraub – mail@dennistraub.de
Testability




Dennis Traub – Software Development Consultancy        @dtraub – mail@dennistraub.de
Testing the Write Model



                    Command Handlers


                     Domain Model




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Testing the Write Model



                    Command Handlers

                                                  Given that certain Events happened
                     Domain Model




Dennis 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




Dennis 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 emitted


Dennis Traub – Software Development Consultancy                           @dtraub – mail@dennistraub.de
Testing the Read Model




                                                  Thin Read Layer


                                                                Table
                                                                 per
                                                                Query



Dennis Traub – Software Development Consultancy          @dtraub – mail@dennistraub.de
Testing the Read Model




                                                  Thin Read Layer

      Given that certain Events happened
                                                                Table
                                                                 per
                                                                Query



Dennis 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                             Query



Dennis 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                               Query



Dennis Traub – Software Development Consultancy            @dtraub – mail@dennistraub.de
Main Values




Dennis Traub – Software Development Consultancy     @dtraub – mail@dennistraub.de
Main Values




                                           additive only
                       we donβ€˜t            lose information




Dennis Traub – Software Development Consultancy            @dtraub – mail@dennistraub.de
Main Values




                                 linearly scalable and
                           distributable Read Model




Dennis Traub – Software Development Consultancy          @dtraub – mail@dennistraub.de
Main Values




                     every new view can be created
                      from the beginning of time




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Main Values




                       We can come up with new questions
                                        at any time




Dennis Traub – Software Development Consultancy       @dtraub – mail@dennistraub.de
Main Values




                     built-in integration model




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
Proven Technology




Dennis Traub – Software Development Consultancy   @dtraub – mail@dennistraub.de
mature business models
                           move away from Update/Delete
                 and become purely                transactional




Dennis 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 & Answers




Dennis Traub – Software Development Consultancy                                                     @dtraub – mail@dennistraub.de
?

                                        QUESTIONS



Dennis Traub – Software Development Consultancy       @dtraub – mail@dennistraub.de
THANK YOU!
                                         follow me: @dtraub




Dennis Traub – Software Development Consultancy               @dtraub – mail@dennistraub.de

More Related Content

Similar to From DDD to CQRS

Sunny Tech 2019 - Craft Forever
Sunny Tech 2019 - Craft ForeverSunny Tech 2019 - Craft Forever
Sunny Tech 2019 - Craft ForeverCyrille Martraire
Β 
Finding balance of DDD while your application grows
Finding balance of DDD while your application growsFinding balance of DDD while your application grows
Finding balance of DDD while your application growsCarolina Karklis
Β 
Let's go to the whiteboard: how and why software developers use drawings
Let's go to the whiteboard: how and why software developers use drawingsLet's go to the whiteboard: how and why software developers use drawings
Let's go to the whiteboard: how and why software developers use drawingsMauro Cherubini
Β 
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefield
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefieldITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefield
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefieldITCamp
Β 
Agile Architecture (Scrum + DevOps) by Milan Chheda
Agile Architecture (Scrum + DevOps) by Milan ChhedaAgile Architecture (Scrum + DevOps) by Milan Chheda
Agile Architecture (Scrum + DevOps) by Milan ChhedaAgile ME
Β 
DaraBaf
DaraBafDaraBaf
DaraBafdarabaf
Β 
Swarup 7.0 cv
Swarup 7.0 cvSwarup 7.0 cv
Swarup 7.0 cvSwarup Das
Β 
designertoday0809
designertoday0809designertoday0809
designertoday0809tutorialsruby
Β 
designertoday0809
designertoday0809designertoday0809
designertoday0809tutorialsruby
Β 
Soliworks presentation
Soliworks presentationSoliworks presentation
Soliworks presentationSimranjit Singh
Β 
BDD presentation
BDD presentationBDD presentation
BDD presentationtemebele
Β 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumNLJUG
Β 
DNetZone Corporate profile
DNetZone Corporate profileDNetZone Corporate profile
DNetZone Corporate profileDhawal Damania
Β 
Dashlane Triple Track
Dashlane Triple TrackDashlane Triple Track
Dashlane Triple TrackDashlane
Β 

Similar to From DDD to CQRS (20)

Sunny Tech 2019 - Craft Forever
Sunny Tech 2019 - Craft ForeverSunny Tech 2019 - Craft Forever
Sunny Tech 2019 - Craft Forever
Β 
Finding balance of DDD while your application grows
Finding balance of DDD while your application growsFinding balance of DDD while your application grows
Finding balance of DDD while your application grows
Β 
Let's go to the whiteboard: how and why software developers use drawings
Let's go to the whiteboard: how and why software developers use drawingsLet's go to the whiteboard: how and why software developers use drawings
Let's go to the whiteboard: how and why software developers use drawings
Β 
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefield
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefieldITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefield
ITCamp 2012 - Sergiu Damian - Architectural decisions on the battlefield
Β 
DOMAIN DRIVER DESIGN
DOMAIN DRIVER DESIGNDOMAIN DRIVER DESIGN
DOMAIN DRIVER DESIGN
Β 
DDD knowledge sharing
DDD knowledge sharingDDD knowledge sharing
DDD knowledge sharing
Β 
Domain driven design - Part I
Domain driven design - Part IDomain driven design - Part I
Domain driven design - Part I
Β 
Agile Architecture (Scrum + DevOps) by Milan Chheda
Agile Architecture (Scrum + DevOps) by Milan ChhedaAgile Architecture (Scrum + DevOps) by Milan Chheda
Agile Architecture (Scrum + DevOps) by Milan Chheda
Β 
DDD In Agile
DDD In Agile   DDD In Agile
DDD In Agile
Β 
DaraBaf
DaraBafDaraBaf
DaraBaf
Β 
Swarup 7.0 cv
Swarup 7.0 cvSwarup 7.0 cv
Swarup 7.0 cv
Β 
designertoday0809
designertoday0809designertoday0809
designertoday0809
Β 
designertoday0809
designertoday0809designertoday0809
designertoday0809
Β 
Soliworks presentation
Soliworks presentationSoliworks presentation
Soliworks presentation
Β 
BDD presentation
BDD presentationBDD presentation
BDD presentation
Β 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten Deinum
Β 
Factors of cost for 3d exterior rendering
Factors of cost for 3d exterior rendering Factors of cost for 3d exterior rendering
Factors of cost for 3d exterior rendering
Β 
DNetZone Corporate profile
DNetZone Corporate profileDNetZone Corporate profile
DNetZone Corporate profile
Β 
Product Development Brochure
Product Development BrochureProduct Development Brochure
Product Development Brochure
Β 
Dashlane Triple Track
Dashlane Triple TrackDashlane Triple Track
Dashlane Triple Track
Β 

More from Dennis Traub

Application Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesApplication Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesDennis Traub
Β 
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandServerless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandDennis Traub
Β 
Serverless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupServerless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupDennis Traub
Β 
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenCloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenDennis Traub
Β 
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Dennis Traub
Β 
Taming the Monolith
Taming the MonolithTaming the Monolith
Taming the MonolithDennis Traub
Β 
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015Dennis Traub
Β 
DDD Modeling Workshop
DDD Modeling WorkshopDDD Modeling Workshop
DDD Modeling WorkshopDennis Traub
Β 

More from Dennis Traub (8)

Application Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for MicroservicesApplication Integration Patterns (not only) for Microservices
Application Integration Patterns (not only) for Microservices
Β 
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, PolandServerless SecOps Automation on AWS at AWS UG Krakow, Poland
Serverless SecOps Automation on AWS at AWS UG Krakow, Poland
Β 
Serverless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User GroupServerless Security Automation on AWS - Hamburg AWS User Group
Serverless Security Automation on AWS - Hamburg AWS User Group
Β 
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, SolingenCloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Cloud ist keine Strategie - Keynote des AWS Cloud Day, Solingen
Β 
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Cloud ist keine Strategie - AWS Tech Community Summit Cologne, 2017
Β 
Taming the Monolith
Taming the MonolithTaming the Monolith
Taming the Monolith
Β 
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
DDD / Microservices @ Trivento Spring Camp, Utrecht, 2015
Β 
DDD Modeling Workshop
DDD Modeling WorkshopDDD Modeling Workshop
DDD Modeling Workshop
Β 

Recently uploaded

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
Β 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
Β 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
Β 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
Β 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
Β 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
Β 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
Β 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vΓ‘zquez
Β 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
Β 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
Β 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
Β 
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot ModelDeepika Singh
Β 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
Β 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
Β 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
Β 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
Β 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
Β 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
Β 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
Β 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Β 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Β 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
Β 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Β 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Β 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Β 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Β 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Β 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Β 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Β 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
Β 
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls πŸ₯° 8617370543 Service Offer VIP Hot Model
Β 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
Β 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Β 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
Β 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Β 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Β 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Β 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Β 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
Β 

From DDD to CQRS

  • 1. From DDD to CQRS presented by Dennis Traub .NET Usergroup Bern - 19. MΓ€rz 2013 Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 2. 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 @dtraub Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 3. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 4. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 5. The β€žBlue Bookβ€œ by Eric Evans Image Placeholder Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 6. 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
  • 7. 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
  • 8. donβ€˜t build one big model that works for everyone Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 9. the tactical Building Blocks we donβ€˜t use DDD when there is no value in formalizing the problem Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 10. we only use DDD in parts where we get a competitive advantage Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 11. we focus our effort and resources on the most important subdomain Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 12. a.k.a. The Core Domain Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 13. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 14. Presentation Layer Application Services Domain / Business Model / BLL DAL / O/R-Mapper Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 15. 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 limitiations Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 16. 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 stuff Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 17. And: If the model is basically CRUD where does Business Logic live? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 18. 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 Loading Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 19. the S in SOLID Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 20. Single Responsibility Principle just because we can doesnβ€˜t mean we should Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 21. why do we try to build One Model to Rule Them All? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 22. reading and writing are completely different from eachother Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 23. Sometimes itβ€˜s cheaper to do two things than dealing with the trade-offs Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 24. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 25. Command Query Separation Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 26. 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 Meyer Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 27. Command Query Separation (CQS) in other words: Asking a question should not change the answer Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 28. Command/Query Responsability Segregation Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 29. CQS on an Architectural Level Queries Commands Project Details Project List Project Data Store Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 30. Queries and Projection (Read) Show something Thin Read Layer Data Store Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 31. Thin Read Layer Concerns: 1 Filtering, Scope 2 Data Presentation Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 32. Thin Read Layer Attributes: 1 Data-Oriented 2 Indexable 3 Can be denormalized and distributed for fast access 4 Only Structure Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 33. Behavior and Modification (Write) Do something Command Handler Domain Model O/R-Mapper Data Store Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 34. Domain Model Concerns: 1 Business Logic 2 Validation Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 35. Domain Model Attributes: 1 Normalized 2 Transactional 3 Object-Oriented 4 Persistence Ignorant 5 Only Behavior Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 36. Commands Refactor Application Service Calls to Objects 1 Serializable 2 Can be enveloped 3 Can be intercepted 4 Can be enriched 5 Communicate intent Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 37. 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
  • 38. Command Handlers Rule of thumb: One Command Handler per use Case Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 39. This is CQRS Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Data Store Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 40. BREAK Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 41. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 42. Domain Event Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 43. Domain Event captures the memory of something interesting affecting the domain Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 44. Domain Event the essence is to capture events that trigger a change to the state Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 45. Domain Event event objects are processed to cause the respective change Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 46. Domain Event and stored to provide an audit log Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 47. Shopping Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 48. we donβ€˜t know: What led to this state? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 49. Added to Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 50. Added Added to to Cart Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 51. Added Added Added to to to Cart Cart Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 52. Added Added Added Removed to to to from Cart Cart Cart Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 53. Which model contains more information? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 54. Shopping Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 55. Added Added Added Removed to to to from Cart Cart Cart Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 56. what if we capture every single event? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 57. … and reproduce state from this stream of events? Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 58. An Event Stream … Added Added Added Removed to to to from Cart Cart Cart Cart Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 59. 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
  • 60. 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
  • 61. 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
  • 62. 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
  • 63. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 64. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Data Store Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 65. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer SQL Data Store Views Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 66. 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
  • 67. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer SELECT * FROM … Table Data Store per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 68. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Table Data Store per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 69. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Table Data Store per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 70. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Event Table Data Store per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 71. Client Commands Queries Command Handlers Domain Model O/R Mapper Thin Read Layer Event Event Event Table Data Store per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 72. Simplified: Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 73. Events Domain Read Model Commands DTOs Client Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 74. Some Code Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 75. Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 76. Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 77. if ISBN exists in ShoppingCartDetails Increase Amount else Add New Row Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 78. if Shopping Cart ID exists in ShoppingCartSummary Increase NumberOfItems Add OfferedPrice to TotalAmount else Add New Row Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 79. Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 80. Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 81. if Amount > 1 ShoppingCartDetails Decrease Amount else Delete Row Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 82. Subtract OfferedPrice to TotalAmount Decrease NumberOfItems Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 83. Testability Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 84. Testing the Write Model Command Handlers Domain Model Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 85. Testing the Write Model Command Handlers Given that certain Events happened Domain Model Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 86. Testing the Write Model When a specific Command is sent Command Handlers Given that certain Events happened Domain Model Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 87. 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 emitted Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 88. Testing the Read Model Thin Read Layer Table per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 89. Testing the Read Model Thin Read Layer Given that certain Events happened Table per Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 90. Testing the Read Model Thin Read Layer Given that certain Events happened Table per When a specific Event happens Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 91. 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 Query Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 92. Main Values Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 93. Main Values additive only we donβ€˜t lose information Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 94. Main Values linearly scalable and distributable Read Model Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 95. Main Values every new view can be created from the beginning of time Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 96. Main Values We can come up with new questions at any time Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 97. Main Values built-in integration model Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 98. Proven Technology Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 99. mature business models move away from Update/Delete and become purely transactional Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 100. Human resources Medicine Bookkeeping Banking Finances Government … Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 101. 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 & Answers Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 102. ? QUESTIONS Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de
  • 103. THANK YOU! follow me: @dtraub Dennis Traub – Software Development Consultancy @dtraub – mail@dennistraub.de