SlideShare uma empresa Scribd logo
1 de 57
Baixar para ler offline
Change the Rules



Rethink you architecture with
           CQRS
Change the Rules




Who are those guys?

INTRODUCTION
Change the Rules
Change the Rules
Change the Rules


                  Agenda
•   Introduction
•   Current architectures & problems
•   CQRS
•   Food for thought
Change the Rules
Change the Rules


Huidige architecturen




      bron: .NET Application Architecture Guide 2.0
Change the Rules


Huidige architecturen
       Presentation layer




       Application layer




           Data layer
Change the Rules


multi-tier
 Presentation layer




   Domain layer




     Data layer
Change the Rules

                                                 Update DTO

                                           Presentation layer
                                      Request
                                        DTO




                          Map DTO

                                                Domain layer
        Request                       Request
          DTO                           DTO



       Map DTO                       Map DTO

                                                 Data layer
Query data   Query data       Query data   Query data
Change the Rules

                                                 Update DTO

                                           Presentation layer
                                      Request
                                                               Send DTO
                                        DTO




                          Map DTO                                               Map DTO

                                                Domain layer
        Request                       Request                    Send                             Send
          DTO                           DTO                      DTO                              DTO



       Map DTO                       Map DTO                     Map DTO                     Map DTO

                                                 Data layer
Query data   Query data       Query data   Query data    Write data     Write data   Write data      Write data
Change the Rules




“A single model cannot be appropriate for
reporting, searching, and transactional
behaviors.” – Greg Young
Change the Rules




“Doordat software processen kan
automatiseren stelt het ons in staat deze
verder op te schalen dan ooit tevoren.“
Change the Rules




“Every method should either be a
command that performs an action, or a
query that returns data to the caller, but
not both.” – Bertrand Meyer
Change the Rules




Presentation layer




  Domain layer




    Data layer
Change the Rules




             Presentation layer




Data layer                        Domain layer
Change the Rules




             Presentation layer




Data layer                        Domain layer
Change the Rules




                          Presentation layer




Read focus                                            State transition focus



             Data layer                        Domain layer
Change the Rules




                               Presentation layer



                          Queries            Commands
Read focus                                                     State transition focus



             Data layer                                 Domain layer
Change the Rules




                               Presentation layer



                          Queries            Commands
Read focus                                                     State transities focus



             Read layer                                 Domain layer
Change the Rules




Here we go!

FROM CONCEPT TO ARCHITECTUUR
Change the Rules




User interface
Change the Rules


                     Queries
•   Requests information
•   Is context dependant
•   Is executed many times
•   Should be simple (select * from x where y)

• Examples:
    – Get all products for user X
    – Get total price of all orders of month May
Change the Rules


                     Read side




User interface
Change the Rules


                         Read side




                 Read databases




User interface
Change the Rules


                         Read side




                 Read databases




                     Facade




User interface
Change the Rules


                          Read side




                 Read databases




                     Facade




                  DTO’s
User interface
Change the Rules


                 Read side
•   Focus on data needs
•   Optimized for reading
•   Can contain multiple models if needed
•   Can be denormalized
•   Facades should be minimized
Change the Rules




“State transitions are an important part of
our problem space and should be modeled
within our domain.” – Greg Young
Change the Rules


                 Commands
• Causes a state transition
• Contains the intend of the user
• Exists in a bounded context

• Examples:
  –   AddProductToShoppingCart
  –   PurchaseOrder
  –   MoveUserToNewAddress
  –   CorrectAddressForUser
Change the Rules


         Commands example



Create                                    Remove
         Add item   Add item   Add item            Purchase
 Cart                                      item
Change the Rules


Write side                                                Read side




                                                 Read databases




                                                     Facade



             Commandhandlers

                     commands                     DTO’s
                                User interface
Change the Rules


Command handler sample
Change the Rules


              The domain
• Validates and handles commands
• Encapsulates behavior
• Build with rich object oriented techniques
Change the Rules


Write side                                                      Read side




                                                       Read databases
                      Repository
             Domein




                                                           Facade



               Commandhandlers

                           commands                     DTO’s
                                      User interface
Change the Rules


Write side                                                          Read side




                                      ?
                                                           Read databases
                      Repository
             Domein




                                                               Facade



               Commandhandlers

                           commands                         DTO’s
                                          User interface
Change the Rules


             Domain events
• Result of a command
• Represents a event

• Examples
  – ProductAddedToShoppingCart
  – OrderPurchased
  – UserMovedToNewAddress
  – AddressCorrectedForUser
Change the Rules


Transitional flow
Change the Rules


Write side                                                          Read side




                                      ?
                                                           Read databases
                      Repository
             Domein




                                                               Facade



               Commandhandlers

                           commands                         DTO’s
                                          User interface
Change the Rules


Write side                                                                                             Read side




                                                                              Denormalizers
                                            Event bus
                                                        events       events




                                   events
                                                                                              Read databases
                      Repository
             Domein




                                                                                                  Facade



               Commandhandlers

                           commands                                                            DTO’s
                                                           User interface
Change the Rules


Denormalizer sample
Change the Rules


 Write side                                                                                                 Read side




                                                                                   Denormalizers
                                                 Event bus
                                                             events       events


                       events




                                        events
Event store
                                                                                                   Read databases
                           Repository
              Domein




                                                                                                       Facade



                Commandhandlers

                                commands                                                            DTO’s
                                                                User interface
Change the Rules


                 Event store
•   Contains all domain events
•   Does not need to be relational
•   Contains the audit log
•   Read models can (re)build themself of it
•   The domain uses it to get the current state
Change the Rules


 Write side                                                                                                     Read side




                                                                                       Denormalizers
                                                 Event bus
                                                             events           events


                       events




                                        events
                                                                      queue
Event store
                                                                                                       Read databases
                           Repository
              Domein




                                                                                                           Facade



                Commandhandlers

                                commands                                                                DTO’s
                                                                User interface
Change the Rules


Application flow
Change the Rules


            CQRS Wrapup
• The domain receives commands and
  publishes domain events.
• All state changes are represented by
domain Events
• The read models are updated as a result of
  the published Events
• All Queries go directly to the read models,
  the domain model is not involved
Change the Rules


                Benefits
• Fully encapsulated domain that only
  exposes behavior
Change the Rules


                Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
Change the Rules


                 Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
• Bullet-proof auditing and historical tracing
Change the Rules


                 Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
• Bullet-proof auditing and historical tracing
• No object-relational impedance mismatch
Change the Rules


                 Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
• Bullet-proof auditing and historical tracing
• No object-relational impedance mismatch
• Optimized and multiple read models
Change the Rules


                 Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
• Bullet-proof auditing and historical tracing
• No object-relational impedance mismatch
• Optimized and multiple read models
• Testability
Change the Rules


                 Benefits
• Fully encapsulated domain that only
  exposes behavior
• Keep users intent
• Bullet-proof auditing and historical tracing
• No object-relational impedance mismatch
• Optimized and multiple read models
• Testability
• Easy integration with external systems
Change the Rules


              Consequences
•   Learning curve
•   Overhead for simple CRUD
•   Data duplication
•   Introducing an new architecture has a big
    impact
Change the Rules


          Food for thought
• Should your read model even contains a
  relational database?
• What does this mean for requirement
  engineering?
• What does this mean for outsourcing?
• What does this mean for DBA?
Change the Rules


You’ve been a great audience!
Change the Rules


           Reference material
•   Podcast with Greg Young
•   MyShop reference architecture
•   Ncqrs framework
•   InfoQ: Unshackle Your Domain

Mais conteúdo relacionado

Semelhante a Rethink your architecture with CQRS

Datastage coursecontent
Datastage coursecontentDatastage coursecontent
Datastage coursecontentAmit Sharma
 
Ibm data stage implementing etl solution using ibm datastage
Ibm data stage  implementing etl solution using ibm datastageIbm data stage  implementing etl solution using ibm datastage
Ibm data stage implementing etl solution using ibm datastagebispsolutions
 
Web 2.0 And The End Of DITA
Web 2.0 And The End Of DITAWeb 2.0 And The End Of DITA
Web 2.0 And The End Of DITAJoe Gollner
 
OSS Presentation Keynote by Hal Stern
OSS Presentation Keynote by Hal SternOSS Presentation Keynote by Hal Stern
OSS Presentation Keynote by Hal SternOpenStorageSummit
 
Linking Data and Actions on the Web
Linking Data and Actions on the WebLinking Data and Actions on the Web
Linking Data and Actions on the WebStuart Charlton
 
Software-Defined Networking , Survey of HotSDN 2012
Software-Defined Networking , Survey of HotSDN 2012Software-Defined Networking , Survey of HotSDN 2012
Software-Defined Networking , Survey of HotSDN 2012Jason TC HOU (侯宗成)
 
All Aboard the Databus
All Aboard the DatabusAll Aboard the Databus
All Aboard the DatabusAmy W. Tang
 
Demo Etom Information Structure
Demo Etom Information StructureDemo Etom Information Structure
Demo Etom Information StructureSergey Khylevich
 
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...IT Arena
 
Exploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliExploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliCarl Steinbach
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architectureandreaskallberg
 
Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Sumant Tambe
 
Lap Around Sql Azure
Lap Around Sql AzureLap Around Sql Azure
Lap Around Sql AzureAnko Duizer
 
Summer Training In Dotnet
Summer Training In DotnetSummer Training In Dotnet
Summer Training In DotnetDUCC Systems
 
Summer training in dotnet
Summer training in dotnetSummer training in dotnet
Summer training in dotnetDUCC Systems
 
CS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceCS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceJ Singh
 
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...Vedanta Barooah
 
Vortex Tutorial Part II
Vortex Tutorial Part IIVortex Tutorial Part II
Vortex Tutorial Part IIAngelo Corsaro
 

Semelhante a Rethink your architecture with CQRS (20)

Datastage coursecontent
Datastage coursecontentDatastage coursecontent
Datastage coursecontent
 
Ibm data stage implementing etl solution using ibm datastage
Ibm data stage  implementing etl solution using ibm datastageIbm data stage  implementing etl solution using ibm datastage
Ibm data stage implementing etl solution using ibm datastage
 
Web 2.0 And The End Of DITA
Web 2.0 And The End Of DITAWeb 2.0 And The End Of DITA
Web 2.0 And The End Of DITA
 
OSS Presentation Keynote by Hal Stern
OSS Presentation Keynote by Hal SternOSS Presentation Keynote by Hal Stern
OSS Presentation Keynote by Hal Stern
 
Linking Data and Actions on the Web
Linking Data and Actions on the WebLinking Data and Actions on the Web
Linking Data and Actions on the Web
 
Software-Defined Networking , Survey of HotSDN 2012
Software-Defined Networking , Survey of HotSDN 2012Software-Defined Networking , Survey of HotSDN 2012
Software-Defined Networking , Survey of HotSDN 2012
 
All Aboard the Databus
All Aboard the DatabusAll Aboard the Databus
All Aboard the Databus
 
3 design
3 design3 design
3 design
 
DA_MAP
DA_MAPDA_MAP
DA_MAP
 
Demo Etom Information Structure
Demo Etom Information StructureDemo Etom Information Structure
Demo Etom Information Structure
 
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
Dennis Doomen. Using OWIN, Webhooks, Event Sourcing and the Onion Architectur...
 
Exploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliExploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with Dali
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++Standardizing the Data Distribution Service (DDS) API for Modern C++
Standardizing the Data Distribution Service (DDS) API for Modern C++
 
Lap Around Sql Azure
Lap Around Sql AzureLap Around Sql Azure
Lap Around Sql Azure
 
Summer Training In Dotnet
Summer Training In DotnetSummer Training In Dotnet
Summer Training In Dotnet
 
Summer training in dotnet
Summer training in dotnetSummer training in dotnet
Summer training in dotnet
 
CS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduceCS 542 Parallel DBs, NoSQL, MapReduce
CS 542 Parallel DBs, NoSQL, MapReduce
 
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...
Accelerating It Migration Success With A Rock Solid Hp And Red Hat Enterprise...
 
Vortex Tutorial Part II
Vortex Tutorial Part IIVortex Tutorial Part II
Vortex Tutorial Part II
 

Mais de Pieter Joost van de Sande (12)

Actor Model
Actor ModelActor Model
Actor Model
 
Microservices
MicroservicesMicroservices
Microservices
 
Microservices
MicroservicesMicroservices
Microservices
 
Werckers path to Go
Werckers path to GoWerckers path to Go
Werckers path to Go
 
Lessons for developers - long edition
Lessons for developers  - long editionLessons for developers  - long edition
Lessons for developers - long edition
 
Introduction to (n)CQRS
Introduction to (n)CQRSIntroduction to (n)CQRS
Introduction to (n)CQRS
 
Lessons for developers
Lessons for developersLessons for developers
Lessons for developers
 
Domain Driven Design fundamentals
Domain Driven Design fundamentalsDomain Driven Design fundamentals
Domain Driven Design fundamentals
 
Introduction to Spec#
Introduction to Spec#Introduction to Spec#
Introduction to Spec#
 
C#, What Is Next?
C#, What Is Next?C#, What Is Next?
C#, What Is Next?
 
XNA presentation
XNA presentationXNA presentation
XNA presentation
 
Domain Driven Design In C#3.0
Domain Driven Design In C#3.0Domain Driven Design In C#3.0
Domain Driven Design In C#3.0
 

Último

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Rethink your architecture with CQRS

  • 1. Change the Rules Rethink you architecture with CQRS
  • 2. Change the Rules Who are those guys? INTRODUCTION
  • 5. Change the Rules Agenda • Introduction • Current architectures & problems • CQRS • Food for thought
  • 7. Change the Rules Huidige architecturen bron: .NET Application Architecture Guide 2.0
  • 8. Change the Rules Huidige architecturen Presentation layer Application layer Data layer
  • 9. Change the Rules multi-tier Presentation layer Domain layer Data layer
  • 10. Change the Rules Update DTO Presentation layer Request DTO Map DTO Domain layer Request Request DTO DTO Map DTO Map DTO Data layer Query data Query data Query data Query data
  • 11. Change the Rules Update DTO Presentation layer Request Send DTO DTO Map DTO Map DTO Domain layer Request Request Send Send DTO DTO DTO DTO Map DTO Map DTO Map DTO Map DTO Data layer Query data Query data Query data Query data Write data Write data Write data Write data
  • 12. Change the Rules “A single model cannot be appropriate for reporting, searching, and transactional behaviors.” – Greg Young
  • 13. Change the Rules “Doordat software processen kan automatiseren stelt het ons in staat deze verder op te schalen dan ooit tevoren.“
  • 14. Change the Rules “Every method should either be a command that performs an action, or a query that returns data to the caller, but not both.” – Bertrand Meyer
  • 15. Change the Rules Presentation layer Domain layer Data layer
  • 16. Change the Rules Presentation layer Data layer Domain layer
  • 17. Change the Rules Presentation layer Data layer Domain layer
  • 18. Change the Rules Presentation layer Read focus State transition focus Data layer Domain layer
  • 19. Change the Rules Presentation layer Queries Commands Read focus State transition focus Data layer Domain layer
  • 20. Change the Rules Presentation layer Queries Commands Read focus State transities focus Read layer Domain layer
  • 21. Change the Rules Here we go! FROM CONCEPT TO ARCHITECTUUR
  • 23. Change the Rules Queries • Requests information • Is context dependant • Is executed many times • Should be simple (select * from x where y) • Examples: – Get all products for user X – Get total price of all orders of month May
  • 24. Change the Rules Read side User interface
  • 25. Change the Rules Read side Read databases User interface
  • 26. Change the Rules Read side Read databases Facade User interface
  • 27. Change the Rules Read side Read databases Facade DTO’s User interface
  • 28. Change the Rules Read side • Focus on data needs • Optimized for reading • Can contain multiple models if needed • Can be denormalized • Facades should be minimized
  • 29. Change the Rules “State transitions are an important part of our problem space and should be modeled within our domain.” – Greg Young
  • 30. Change the Rules Commands • Causes a state transition • Contains the intend of the user • Exists in a bounded context • Examples: – AddProductToShoppingCart – PurchaseOrder – MoveUserToNewAddress – CorrectAddressForUser
  • 31. Change the Rules Commands example Create Remove Add item Add item Add item Purchase Cart item
  • 32. Change the Rules Write side Read side Read databases Facade Commandhandlers commands DTO’s User interface
  • 33. Change the Rules Command handler sample
  • 34. Change the Rules The domain • Validates and handles commands • Encapsulates behavior • Build with rich object oriented techniques
  • 35. Change the Rules Write side Read side Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 36. Change the Rules Write side Read side ? Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 37. Change the Rules Domain events • Result of a command • Represents a event • Examples – ProductAddedToShoppingCart – OrderPurchased – UserMovedToNewAddress – AddressCorrectedForUser
  • 39. Change the Rules Write side Read side ? Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 40. Change the Rules Write side Read side Denormalizers Event bus events events events Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 42. Change the Rules Write side Read side Denormalizers Event bus events events events events Event store Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 43. Change the Rules Event store • Contains all domain events • Does not need to be relational • Contains the audit log • Read models can (re)build themself of it • The domain uses it to get the current state
  • 44. Change the Rules Write side Read side Denormalizers Event bus events events events events queue Event store Read databases Repository Domein Facade Commandhandlers commands DTO’s User interface
  • 46. Change the Rules CQRS Wrapup • The domain receives commands and publishes domain events. • All state changes are represented by domain Events • The read models are updated as a result of the published Events • All Queries go directly to the read models, the domain model is not involved
  • 47. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior
  • 48. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent
  • 49. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent • Bullet-proof auditing and historical tracing
  • 50. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent • Bullet-proof auditing and historical tracing • No object-relational impedance mismatch
  • 51. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent • Bullet-proof auditing and historical tracing • No object-relational impedance mismatch • Optimized and multiple read models
  • 52. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent • Bullet-proof auditing and historical tracing • No object-relational impedance mismatch • Optimized and multiple read models • Testability
  • 53. Change the Rules Benefits • Fully encapsulated domain that only exposes behavior • Keep users intent • Bullet-proof auditing and historical tracing • No object-relational impedance mismatch • Optimized and multiple read models • Testability • Easy integration with external systems
  • 54. Change the Rules Consequences • Learning curve • Overhead for simple CRUD • Data duplication • Introducing an new architecture has a big impact
  • 55. Change the Rules Food for thought • Should your read model even contains a relational database? • What does this mean for requirement engineering? • What does this mean for outsourcing? • What does this mean for DBA?
  • 56. Change the Rules You’ve been a great audience!
  • 57. Change the Rules Reference material • Podcast with Greg Young • MyShop reference architecture • Ncqrs framework • InfoQ: Unshackle Your Domain