SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Idiomatic Domain Driven Design:
implementing CQRS
Andrea Saltarello
CEO @ managed/designs
andysal@gmail.com
http://twitter.com/andysal74
http://slideshare.net/andysal
Who I am
1. CEO @ Managed Designs, striving to discover the
perfect «sustainable software development process»
• Customer has to be satisfied and pay
• Supplier has to have a reasonable markup
• Team members should be satisfied with their work
2. Founder and leader of UGIdotNET (first Italian .NET
User Group): I need to share experiences peer to peer
3. (Co)Author (together with Dino) of .NET: Architecting
Applications for the Enterprise, by Microsoft Press
4. Basically, a software developer 
What’s DDD?
Domain Driven Design:
• Is not a methodology
• Is not an architecture
• Is not a silver bullet
• Is an approach aimed to tackle the complexity of software
development; its main assets are:
–Bounded Context
–Ubiquitous Language
–Aggregates
–(Events)
Ubiquitous Language
It’s the language spoken by all the people that
work on a project; the UL spans from the
documentation to the source code.
Basically, technicians should adopt the language
spoken by the business in order to reduce
friction
Bounded Context
A Bounded Context is a bounduary whithin which a
specific ubiquitous language applies
A system is a composition (Map) of (bounded) contexts
(e.g.: web store, accountability, delivery&shipment …),
speaking one to each other by means of some kind of
API.
Due to the decoupling of contexts, we can use an ad hoc
architecture for every context
Aggregates
Aggregates are atomic clusters of “objects” that exist
and interact inside a specific BC: every Aggregate acts
as the “(both) data and behaviour” composition of an
important concept which exists within the BC itself.
• Basically, a “DDD oriented” system does coordinate
the work of aggregates
• The whole set of aggregates existing within a specific
BC is the BC’s Domain Model.
• Should a specific behaviour exceed an Aggregate’s
bonduary, it will be implemented as a (Domain)
Service
• Model + Services == (Domain) Layer
Andrea vs. DDD, A.D. 2004
Got it: a system is a composition Map of
Bounded Contexts, each one sporting a Domain
Layer created after an Ubiquitous Language.
Awesome! Super Cool! Now… How the hell can
we translate this in code? 
2004: a Domain (Model) Odissey
DEMO
Domain Model (Voucher, NSK)
Is Domain Model broken?
Domain Model is (almost) ok, but to follow the
“Blue Book style” is pretty hard and requires a
lot of tradeoffs: is there a different way to have
the same approach applied?
DDD has twodistinct parts. You always need one and can
sometimes happily ignore the other.
Analytical
Strategic
Valuable to everybody and every project
Blue book’s Domain Model is just one “supporting architecture”,
though the one being originally recommended
Command Query Responsibility Segregation
A single model cannot be appropriate for
reporting, searching and transactional
behaviours
[Greg Young]
CQRS at a glance
Query Command
CQRS in a nutshell
«Doing CQRS» means separating the stack that reads
data (query) from the one that can alter the system’s
state (command), each one having its own ad hoc
«model»
All the actions that the system is capable of are
expressed as Commands. To sum it up:
1. A user An actor ask the system to execute a
command
2. Command execution alters the system’s state
3. The read model is used in order to query for
(updated) data
What’s a «MODEL», anyway?
We’re not trying to have a model which
faithfully represents the world, but one that
works within a bounded context
.Net DeveloperDays 2014
Mercator projection (1569)
.Net DeveloperDays 2014
That’s the world map we’re used to and… It’s wrong, but it
actually works (from a certain point of view)
Galls-Peters projection (1885 ⊕ 1973)
.Net DeveloperDays 2014
The Query side of the Force
The «Read Model» can be served in different flavours,
such as:
• Plain SQL
• (Micro) O/RM
• Services (xml, json, DTOs, …)
• LET (Layered Expression Trees)
Layered Expression Trees (LET idiom)
As a business unit manager, I want to collect credits due to
unpaid outgoing invoices #ubiquitouslanguage #nuffsaid
Database.OutgoingInvoices.
.PerBusinessUnit(businessUnitId)
.ExpiredOnly()
.Select(i => new {InvoiceNumber = i.Number, CustomerId =
i.Customer.Id})
.AsParallel()
.ForAll(i => bus.Send(new
CollectDebtCommand(i.InvoiceNumber, i.CustomerId)));
DEMO
Layered Expression Trees
The Command side of the Force
Sorry, non silver bullet available for implementing
commands, too. Common choices:
• Transaction Script
• Event Sourcing (we will talk about this tomorrow)
CQRS feat. Transaction Script
Transaction Script
[P of EAA, 110]
Organizes business logic by procedures where each
procedure handles a single request from the
presentation.
Commands are «modeled» as functions, each one
representing one action that the system is capable of
DEMO
Transaction Script feat. CQRS
Next stop: Events. See you tomorrow 
It really became clear to me in the last couple of years
that we need a new building block and that is the
Domain Event.
[Eric Evans]
An event is something that has happened in the past.
[Greg Young]
A domain event … captures the memory of something
interesting which affects the domain
[Martin Fowler]
Bibliography
[DDD] Domain Driven Design, Eric Evans , Addison-Wesley
[NAAE] Microsoft .NET: Architecting Applications for the
Enterprise (2° ed.), Andrea Saltarello & Dino Esposito,
Microsoft Press
[MERP] Merp, https://naa4e.codeplex.com/
Idiomatic Domain Driven Design: implementing CQRS

Contenu connexe

Similaire à Idiomatic Domain Driven Design: implementing CQRS

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)Tom Kocjan
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)IT Arena
 
Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15Mark Windholtz
 
Model Driven Architectures
Model Driven ArchitecturesModel Driven Architectures
Model Driven ArchitecturesLalit Kale
 
Domain Driven Design - Building Blocks
Domain Driven Design - Building BlocksDomain Driven Design - Building Blocks
Domain Driven Design - Building BlocksMark Windholtz
 
Domain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic PatternsDomain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic PatternsMark Windholtz
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven DesignNicolò Pignatelli
 
Excavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsExcavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsUwe Friedrichsen
 
Introduction to Domain-Driven Design
Introduction to Domain-Driven DesignIntroduction to Domain-Driven Design
Introduction to Domain-Driven DesignR-P-Azevedo
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)siouxhotornot
 
Domain specific modelling (DSM)
Domain specific modelling (DSM)Domain specific modelling (DSM)
Domain specific modelling (DSM)PG Scholar
 
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"GlobalLogic Ukraine
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPChris Renner
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignMuhammad Ali
 

Similaire à Idiomatic Domain Driven Design: implementing CQRS (20)

Domain Driven Design (DDD)
Domain Driven Design (DDD)Domain Driven Design (DDD)
Domain Driven Design (DDD)
 
Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)Domain-Driven Design (Artur Trosin Product Stream)
Domain-Driven Design (Artur Trosin Product Stream)
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15Domain Driven Design - Distillation - Chapter 15
Domain Driven Design - Distillation - Chapter 15
 
Model Driven Architectures
Model Driven ArchitecturesModel Driven Architectures
Model Driven Architectures
 
Domain Driven Design - Building Blocks
Domain Driven Design - Building BlocksDomain Driven Design - Building Blocks
Domain Driven Design - Building Blocks
 
Domain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic PatternsDomain Driven Design Big Picture Strategic Patterns
Domain Driven Design Big Picture Strategic Patterns
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Brownfield Domain Driven Design
Brownfield Domain Driven DesignBrownfield Domain Driven Design
Brownfield Domain Driven Design
 
Excavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsExcavating the knowledge of our ancestors
Excavating the knowledge of our ancestors
 
Introduction to Domain-Driven Design
Introduction to Domain-Driven DesignIntroduction to Domain-Driven Design
Introduction to Domain-Driven Design
 
DDD In Agile
DDD In Agile   DDD In Agile
DDD In Agile
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Let's talk about... Microservices
Let's talk about... MicroservicesLet's talk about... Microservices
Let's talk about... Microservices
 
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
Sioux Hot-or-Not: Model Driven Software Development (Markus Voelter)
 
Domain specific modelling (DSM)
Domain specific modelling (DSM)Domain specific modelling (DSM)
Domain specific modelling (DSM)
 
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 

Plus de Andrea Saltarello

Da Rotor a .NET Core ed indietro: Microsoft <3 Open Source
Da Rotor a .NET Core ed indietro: Microsoft <3 Open SourceDa Rotor a .NET Core ed indietro: Microsoft <3 Open Source
Da Rotor a .NET Core ed indietro: Microsoft <3 Open SourceAndrea Saltarello
 
Never Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignNever Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignAndrea Saltarello
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSAndrea Saltarello
 
How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignAndrea Saltarello
 
Code Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryCode Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryAndrea Saltarello
 
Idiomatic Domain Driven Design
Idiomatic Domain Driven DesignIdiomatic Domain Driven Design
Idiomatic Domain Driven DesignAndrea Saltarello
 
Build a LINQ-enabled Repository
Build a LINQ-enabled RepositoryBuild a LINQ-enabled Repository
Build a LINQ-enabled RepositoryAndrea Saltarello
 
Layered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDLayered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDAndrea Saltarello
 
From relational data to object spaces
From relational data to object spacesFrom relational data to object spaces
From relational data to object spacesAndrea Saltarello
 

Plus de Andrea Saltarello (12)

Da Rotor a .NET Core ed indietro: Microsoft <3 Open Source
Da Rotor a .NET Core ed indietro: Microsoft <3 Open SourceDa Rotor a .NET Core ed indietro: Microsoft <3 Open Source
Da Rotor a .NET Core ed indietro: Microsoft <3 Open Source
 
ASP.NET Core essentials
ASP.NET Core essentialsASP.NET Core essentials
ASP.NET Core essentials
 
Never Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignNever Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven Design
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRS
 
How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven Design
 
ASP.NET MVC: Full Throttle
ASP.NET MVC: Full ThrottleASP.NET MVC: Full Throttle
ASP.NET MVC: Full Throttle
 
Code Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryCode Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled Repository
 
Idiomatic Domain Driven Design
Idiomatic Domain Driven DesignIdiomatic Domain Driven Design
Idiomatic Domain Driven Design
 
Build a LINQ-enabled Repository
Build a LINQ-enabled RepositoryBuild a LINQ-enabled Repository
Build a LINQ-enabled Repository
 
Layered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDLayered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDD
 
From relational data to object spaces
From relational data to object spacesFrom relational data to object spaces
From relational data to object spaces
 
MVC2: non solo tecnologia
MVC2: non solo tecnologiaMVC2: non solo tecnologia
MVC2: non solo tecnologia
 

Dernier

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 

Dernier (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 

Idiomatic Domain Driven Design: implementing CQRS

  • 1.
  • 2. Idiomatic Domain Driven Design: implementing CQRS Andrea Saltarello CEO @ managed/designs andysal@gmail.com http://twitter.com/andysal74 http://slideshare.net/andysal
  • 3. Who I am 1. CEO @ Managed Designs, striving to discover the perfect «sustainable software development process» • Customer has to be satisfied and pay • Supplier has to have a reasonable markup • Team members should be satisfied with their work 2. Founder and leader of UGIdotNET (first Italian .NET User Group): I need to share experiences peer to peer 3. (Co)Author (together with Dino) of .NET: Architecting Applications for the Enterprise, by Microsoft Press 4. Basically, a software developer 
  • 4. What’s DDD? Domain Driven Design: • Is not a methodology • Is not an architecture • Is not a silver bullet • Is an approach aimed to tackle the complexity of software development; its main assets are: –Bounded Context –Ubiquitous Language –Aggregates –(Events)
  • 5. Ubiquitous Language It’s the language spoken by all the people that work on a project; the UL spans from the documentation to the source code. Basically, technicians should adopt the language spoken by the business in order to reduce friction
  • 6. Bounded Context A Bounded Context is a bounduary whithin which a specific ubiquitous language applies A system is a composition (Map) of (bounded) contexts (e.g.: web store, accountability, delivery&shipment …), speaking one to each other by means of some kind of API. Due to the decoupling of contexts, we can use an ad hoc architecture for every context
  • 7. Aggregates Aggregates are atomic clusters of “objects” that exist and interact inside a specific BC: every Aggregate acts as the “(both) data and behaviour” composition of an important concept which exists within the BC itself. • Basically, a “DDD oriented” system does coordinate the work of aggregates • The whole set of aggregates existing within a specific BC is the BC’s Domain Model. • Should a specific behaviour exceed an Aggregate’s bonduary, it will be implemented as a (Domain) Service • Model + Services == (Domain) Layer
  • 8. Andrea vs. DDD, A.D. 2004 Got it: a system is a composition Map of Bounded Contexts, each one sporting a Domain Layer created after an Ubiquitous Language. Awesome! Super Cool! Now… How the hell can we translate this in code? 
  • 9. 2004: a Domain (Model) Odissey
  • 11. Is Domain Model broken? Domain Model is (almost) ok, but to follow the “Blue Book style” is pretty hard and requires a lot of tradeoffs: is there a different way to have the same approach applied?
  • 12. DDD has twodistinct parts. You always need one and can sometimes happily ignore the other. Analytical Strategic Valuable to everybody and every project Blue book’s Domain Model is just one “supporting architecture”, though the one being originally recommended
  • 13. Command Query Responsibility Segregation A single model cannot be appropriate for reporting, searching and transactional behaviours [Greg Young]
  • 14. CQRS at a glance Query Command
  • 15. CQRS in a nutshell «Doing CQRS» means separating the stack that reads data (query) from the one that can alter the system’s state (command), each one having its own ad hoc «model» All the actions that the system is capable of are expressed as Commands. To sum it up: 1. A user An actor ask the system to execute a command 2. Command execution alters the system’s state 3. The read model is used in order to query for (updated) data
  • 16. What’s a «MODEL», anyway? We’re not trying to have a model which faithfully represents the world, but one that works within a bounded context .Net DeveloperDays 2014
  • 17. Mercator projection (1569) .Net DeveloperDays 2014 That’s the world map we’re used to and… It’s wrong, but it actually works (from a certain point of view)
  • 18. Galls-Peters projection (1885 ⊕ 1973) .Net DeveloperDays 2014
  • 19. The Query side of the Force The «Read Model» can be served in different flavours, such as: • Plain SQL • (Micro) O/RM • Services (xml, json, DTOs, …) • LET (Layered Expression Trees)
  • 20. Layered Expression Trees (LET idiom) As a business unit manager, I want to collect credits due to unpaid outgoing invoices #ubiquitouslanguage #nuffsaid Database.OutgoingInvoices. .PerBusinessUnit(businessUnitId) .ExpiredOnly() .Select(i => new {InvoiceNumber = i.Number, CustomerId = i.Customer.Id}) .AsParallel() .ForAll(i => bus.Send(new CollectDebtCommand(i.InvoiceNumber, i.CustomerId)));
  • 22. The Command side of the Force Sorry, non silver bullet available for implementing commands, too. Common choices: • Transaction Script • Event Sourcing (we will talk about this tomorrow)
  • 23. CQRS feat. Transaction Script Transaction Script [P of EAA, 110] Organizes business logic by procedures where each procedure handles a single request from the presentation. Commands are «modeled» as functions, each one representing one action that the system is capable of
  • 25. Next stop: Events. See you tomorrow  It really became clear to me in the last couple of years that we need a new building block and that is the Domain Event. [Eric Evans] An event is something that has happened in the past. [Greg Young] A domain event … captures the memory of something interesting which affects the domain [Martin Fowler]
  • 26. Bibliography [DDD] Domain Driven Design, Eric Evans , Addison-Wesley [NAAE] Microsoft .NET: Architecting Applications for the Enterprise (2° ed.), Andrea Saltarello & Dino Esposito, Microsoft Press [MERP] Merp, https://naa4e.codeplex.com/