SlideShare a Scribd company logo
1 of 18
CQRS & Domain Models Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist
What most architecture looks like
Common Mistakes #1 Assuming that layers == tiers We can deploy the same components both client-side and server-side
But where do business rules go? Here? Here? Here? Here? Here? Here?
Code Reuse On A Pedestal Understanding existing code takes longer than writing new code
Too Much Of A “Good Thing”
For Example - CQRS Queries View Model UI Queries Commands Publish WS Input Validation Validation Rules View Model Updater DB
Common Mistake #2 Assuming that all rules are equally likely to change
Rules We Know How To Handle  In the domain model only: When a customer cancels an order, 	if the order was already shipped, 	charge the customer $$ 	unless customer is {some status} DB
Rules We Struggle With Where to enforce these rules? - First name less than N chars 	- Username must be unique Not Domain Logic! DB
The Domain Model	When To Use It  &  When Not To “If you have complicated and everchanging business rules…” “If you have simple not-null checks and a couple of sums to calculate, a Transaction Script is a better bet” 		-- Martin Fowler, p119 Patterns of Enterprise Application Architecture
Common Mistake #3 Assuming that race conditions affect the domain
Race Conditions Cancel Order Ship Order We think this should fail
What Domain Events Are For What else needs to happen? 	When a customer cancels an order, 	if the order was already shipped, 	charge the customer $$ 	unless customer is {some status} DomainEvents.Raise<InvokeCancellationFee>( 	f => f.OrderId = msg.OrderId );
Consider The Reverse Going to ship a cancelled order Race condition between command & query “One in a million” failure 	  Let it fail asynchronously Email back to the user 	“Sorry, that order doesn’t exist anymore”
Aggregate Mistakes public class Customer { publicvoidMakePreferred() 	{ foreach(Ordero inthis.UnbilledOrders) o.Discount(10.Percent); 	} }
In Closing Avoid the common mistakes: 	#1  Layers & tiers 	#2  Rate of rule change 	#3  Race Conditions Think about aggregates & bounded contexts
Thank you Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist www.UdiDahan.com email@UdiDahan.com

More Related Content

Similar to DDD eXchange 2010: Udi Dahan on Architectural Innovation: CQRS

RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your Domain
Lourens Naudé
 
Cloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptxCloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptx
terewog808
 
The 1990s Called. They Want Their Code Back.
The 1990s Called. They Want Their Code Back.The 1990s Called. They Want Their Code Back.
The 1990s Called. They Want Their Code Back.
Jonathan Oliver
 
Enough Blame for System Performance Issues
Enough Blame for System Performance IssuesEnough Blame for System Performance Issues
Enough Blame for System Performance Issues
Mahesh Vallampati
 

Similar to DDD eXchange 2010: Udi Dahan on Architectural Innovation: CQRS (20)

Event-Driven Architectures Done Right | Tim Berglund, Confluent
Event-Driven Architectures Done Right | Tim Berglund, ConfluentEvent-Driven Architectures Done Right | Tim Berglund, Confluent
Event-Driven Architectures Done Right | Tim Berglund, Confluent
 
Are Transactions Right For You? Using and Not Abusing Transactions
Are Transactions Right For You? Using and Not Abusing TransactionsAre Transactions Right For You? Using and Not Abusing Transactions
Are Transactions Right For You? Using and Not Abusing Transactions
 
Long running processes in DDD
Long running processes in DDDLong running processes in DDD
Long running processes in DDD
 
Active-Active Multi-Region Architectures.pdf
Active-Active Multi-Region Architectures.pdfActive-Active Multi-Region Architectures.pdf
Active-Active Multi-Region Architectures.pdf
 
Fault Handling in SOA Suite 11g
Fault Handling in SOA Suite 11gFault Handling in SOA Suite 11g
Fault Handling in SOA Suite 11g
 
Start Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
Start Up Austin 2017: Production Preview - How to Stop Bad Things From HappeningStart Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
Start Up Austin 2017: Production Preview - How to Stop Bad Things From Happening
 
TDC2018SP | Trilha Ruby - Maior performance no seu sistema com o uso adequado...
TDC2018SP | Trilha Ruby - Maior performance no seu sistema com o uso adequado...TDC2018SP | Trilha Ruby - Maior performance no seu sistema com o uso adequado...
TDC2018SP | Trilha Ruby - Maior performance no seu sistema com o uso adequado...
 
The Art of Gherkin Scripting - Matt Eakin
The Art of Gherkin Scripting - Matt EakinThe Art of Gherkin Scripting - Matt Eakin
The Art of Gherkin Scripting - Matt Eakin
 
RailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your DomainRailswayCon 2010 - Command Your Domain
RailswayCon 2010 - Command Your Domain
 
Cloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptxCloud Services helping in cloud service to be fully knowledgably .pptx
Cloud Services helping in cloud service to be fully knowledgably .pptx
 
Supercharge Your Applications
Supercharge Your ApplicationsSupercharge Your Applications
Supercharge Your Applications
 
DevDay: A Tale of Corda Slack Adventures, R3
DevDay: A Tale of Corda Slack Adventures, R3DevDay: A Tale of Corda Slack Adventures, R3
DevDay: A Tale of Corda Slack Adventures, R3
 
Maior performance no seu sistema com o uso adequado de orm em rails
Maior performance no seu sistema com o uso adequado de orm em railsMaior performance no seu sistema com o uso adequado de orm em rails
Maior performance no seu sistema com o uso adequado de orm em rails
 
Greenfield Development with CQRS
Greenfield Development with CQRSGreenfield Development with CQRS
Greenfield Development with CQRS
 
Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019Building resilient frontend architecture by Monica Lent at FrontCon 2019
Building resilient frontend architecture by Monica Lent at FrontCon 2019
 
SE-Lecture 2A-Requirements.pptx
SE-Lecture 2A-Requirements.pptxSE-Lecture 2A-Requirements.pptx
SE-Lecture 2A-Requirements.pptx
 
The 1990s Called. They Want Their Code Back.
The 1990s Called. They Want Their Code Back.The 1990s Called. They Want Their Code Back.
The 1990s Called. They Want Their Code Back.
 
Enough Blame for System Performance Issues
Enough Blame for System Performance IssuesEnough Blame for System Performance Issues
Enough Blame for System Performance Issues
 
Serverless lessons learned #8 backoff
Serverless lessons learned #8 backoffServerless lessons learned #8 backoff
Serverless lessons learned #8 backoff
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
 

More from Skills Matter

Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
Skills Matter
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
Skills Matter
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
Skills Matter
 

More from Skills Matter (20)

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
 
Serendipity-neo4j
Serendipity-neo4jSerendipity-neo4j
Serendipity-neo4j
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Plug 20110217
Plug   20110217Plug   20110217
Plug 20110217
 
Lug presentation
Lug presentationLug presentation
Lug presentation
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
 
Plug saiku
Plug   saikuPlug   saiku
Plug saiku
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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...
 
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...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

DDD eXchange 2010: Udi Dahan on Architectural Innovation: CQRS

  • 1. CQRS & Domain Models Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist
  • 3. Common Mistakes #1 Assuming that layers == tiers We can deploy the same components both client-side and server-side
  • 4. But where do business rules go? Here? Here? Here? Here? Here? Here?
  • 5. Code Reuse On A Pedestal Understanding existing code takes longer than writing new code
  • 6. Too Much Of A “Good Thing”
  • 7. For Example - CQRS Queries View Model UI Queries Commands Publish WS Input Validation Validation Rules View Model Updater DB
  • 8. Common Mistake #2 Assuming that all rules are equally likely to change
  • 9. Rules We Know How To Handle In the domain model only: When a customer cancels an order, if the order was already shipped, charge the customer $$ unless customer is {some status} DB
  • 10. Rules We Struggle With Where to enforce these rules? - First name less than N chars - Username must be unique Not Domain Logic! DB
  • 11. The Domain Model When To Use It & When Not To “If you have complicated and everchanging business rules…” “If you have simple not-null checks and a couple of sums to calculate, a Transaction Script is a better bet” -- Martin Fowler, p119 Patterns of Enterprise Application Architecture
  • 12. Common Mistake #3 Assuming that race conditions affect the domain
  • 13. Race Conditions Cancel Order Ship Order We think this should fail
  • 14. What Domain Events Are For What else needs to happen? When a customer cancels an order, if the order was already shipped, charge the customer $$ unless customer is {some status} DomainEvents.Raise<InvokeCancellationFee>( f => f.OrderId = msg.OrderId );
  • 15. Consider The Reverse Going to ship a cancelled order Race condition between command & query “One in a million” failure Let it fail asynchronously Email back to the user “Sorry, that order doesn’t exist anymore”
  • 16. Aggregate Mistakes public class Customer { publicvoidMakePreferred() { foreach(Ordero inthis.UnbilledOrders) o.Discount(10.Percent); } }
  • 17. In Closing Avoid the common mistakes: #1 Layers & tiers #2 Rate of rule change #3 Race Conditions Think about aggregates & bounded contexts
  • 18. Thank you Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist www.UdiDahan.com email@UdiDahan.com

Editor's Notes

  1. Same rules for insurance, finance, retail, online gambling, etc.These are technical constraints.We’d expect domain logic like in the previous slide to change often, these rules hardly ever change.
  2. Thousands of years of paper-based business worked around this just fine, even though the latency increased the chance of these “concurrency conflict”