SlideShare a Scribd company logo
Domain-Driven Design
Focus on Knowledge, Efficiency and Maintainability
Gérard Dethier1
1
Guardis / ComodIT
http://www.comodit.com
November 10th 2017 / Geeks Anonymes Liège
Most IT systems consist in the implementation of a set of
processes
For instance, a company selling failure-prone products to coyotes:
registration of a new client
selling
billing
. . .
Many implemented processes share the same structure
Read some stuff from a database
Modify parts of retrieved information while enforcing some rules
Save the modified parts into the database
While structure is simple, details can be complex
When selling an Item to a Client, first check that there are
enough Units available. If it’s the case, remove the Item from
the Stock. If the number of Units in Stock goes below a
given Threshold, the production of new Units should be
triggered. Also, a Line should be added to the last Invoice
not yet emitted. Finally, as soon as the Item is shipped, an
e-mail should be sent to the Coyote.
– An ACME domain expert
Details may change in time
Agile project management implies ever changing requirements
The domain is evolving
Domain experts and developers are not talking the same
language
Domain experts are talking about clients, units, stock,
invoices, . . .
Developers are talking about tables, records, objects, classes,
relations, transactions. . .
. . . and that’s perfectly fine (both languages are the most efficient
when used in their context)!
A common language is needed
Understood by both domain experts and developers
Precise
Flexible
Scalable in domain complexity
The number of processes executed per time unit can be
large
For example, ACME faces:
A growth in client base → many registrations
many orders
many invoices
. . .
Slow execution has a cost
For example:
Less registrations means less clients
Slow invoicing has a bad impact on cash flow
Slow client support might lead to clients leaving
Note that the cost is not necessarily money
Processes execution time must be low
Implementation must be:
Efficient
Scalable
Developers team evolves
Developers might leave → potential loss of knowledge
Team might grow to better respond to change → collaboration
between developers becomes more complex (knowledge
exchange, collisions in code changes. . . )
Domain-Driven Design (DDD) is a framework addressing all
those concerns
Provides a meta-language for domain experts and developers
easing the definition of a common language
Includes the domain description in the code
Defines design rules promoting flexible, efficient and scalable
code, as well as improving collaboration between developers
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
DDD defines a meta-language that can be used to develop a
common language between domain experts and developers
The meta-language looks like other well known “languages”
(OOP, ER model) but is more abstract
The Ubiquitous Language defines the vocabulary that domain
experts and developers will use in their communication and in the
code
10 design element types are available
The Value Object (VO) has a state that does not evolve in
time
It has no identity and is only defined by its value
It’s state is immutable
It can have a behavior (it’s a good practice to put as much
knowledge as possible in VOs)
Examples: contact name, e-mail address, invoice number, . . .
The Entity has a life cycle and an identity
Its state may evolve over time
It is uniquely identified by a key
It’s state is, in general, made of a set of VOs
It may reference other Entities
The Aggregate defines a group of tightly coupled Entities
One single Entity has the role of Aggregate Root
it’s identity is the Aggregate’s identity
it acts as an entry point to Aggregate’s behavior
A set of invariants applies to the Entities part of the Aggregate
No reference can point to any Entity of an Aggregate except the
Aggregate Root
Aggregates are built using Factories
A Factory is stateless
Built Aggregates have all their invariants fulfilled
Aggregates are stored using Repositories
A Repository is stateless
Repositories expose a collection-like interface to perform CRUD
operations
Repositories hide the details of Aggregates’ storage
A behavior not finding its place in any of previous elements
is put in a Service
A Service is stateless (Repositories and Factories are particular
cases of Services)
The choice of putting behavior in a Service rather than in a VO,
Entity, Repository or Factory must be driven by the domain
Modules allow to organize a domain when the number of
elements grows
The only purpose is organization
No behavior
No state
When sub-domains are identified, they can be mapped to
separate Bounded Contexts
A Bounded Context defines a bounday in which a concept has a
unique definition
The same concept can appear in different Bounded Contexts but
with varying definitions
Bounded Contexts generally map to separate pieces of a system
that model a given domain
The Context Map shows the way Bounded Contexts are
linked
A link between 2 Bounded Contexts means they share related
concepts
Links can be annotated with the related concepts
Only one Aggregate can be updated per transaction
The Aggregate Root is acting as the “lock”
At the end of the transaction, all invariants must be true
Domain Events allow consistency rules spanning several
Aggregates
The update of one Aggregate triggers the publication of a Domain
Event
The Domain Event consumption implies the update of another
Aggregate in another transaction
After a sequence of transactions, all invariants are verified
This is called Eventual Consistency
Design elements can be categorized
Stateful Behavioral Stuctural
Value Object • •
Entity • •
Aggregate •
Factory •
Repository •
Service •
Module •
Bounded Context •
Context Map •
Domain Event •
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
Information is spread among elements with varying precision
The structure of the model makes search efficient for
everybody
Tree search → O(logn)
Domain experts and developers understand the model (they built
it together!)
The type of design elements tells if one might find a given type of
information or not (state / behavior / structure)
Deepening of the model does not get crippled by existing
complexity
. . . if information is evenly spread across leaves
→ VOs and Entities are the best places to store information
It is then possible to focus on small pieces of the domain that
need to be deepened
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
Domain experts are generally open to delay the fulfillment of
some constraints
Acceptable delays may vary between a couple of seconds and
days!
Eventual Consistency can therefore be used in a lot of situations,
in particular when fast response time is needed
Small Aggregates are desirable
Smaller (in terms of number of elements) Aggregates → shorter
transactions
Short transactions
→ improved scalability
→ reduced risk of conflict
Perceived execution time for a process → short as only first step
is blocking (following steps run in background)
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
The model is documented by the code
Discussions between domain experts and developers can be put
in the context of actual code as both share a Ubiquitous
Language
No risk of stale external documentation obfuscating the model
A domain expert is actually able to help a developer understand
its own code!
Clear separation of concerns allows parallel improvement of
the model
Several teams can work in parallel on separate Bounded
Contexts
Inside of the same Bounded Context, work can be planned on
separate Aggregates
Risk of conflicting changes is reduced
Weak coupling of Aggregates makes code flexible
Splitting a code base is easier
Risk of “shotgun sugery” when refactoring is reduced
Strong coupling inside of Aggregates makes code robust
Most important invariants are implemented in a highly controlled
environment
Strong coupling inside of an Aggregate makes detection of issues
in case of divergence in a sub-component faster
The size Aggregates is a trade-off. . .
The bigger, the more robust
The smaller, the more efficient
. . . but might also be driven by other requirements
Domain experts might not agree to subdivide some Aggregates
because it may not make sense
Reminder: an Entity inside of an Aggregate which is not the
Aggregate Root cannot be referenced from outside of the
Aggregate
→ if a reference is needed to an Entity, it must be an Aggregate
Root
Outline
The Framework
Knowledge
Efficiency
Maintainability
Conclusion
DDD is a powerful software design methodology
Allowing a deep understanding of the domain by both experts and
developers
Promoting efficiency while allowing to preseve robustness
Improving the maintainability of the code base
It is often considered as “hard”
Differences between design elements is sometimes subtel and
badly understood
Not concrete enough for developers
Too abstract for domain experts
In practice, a lot of technical details have to be solved
Keeping domain model clean
Transport of Domain Events in a distributed environment
Handling of failed Domain Event consumption
Handling of duplicate Domain Event consumptions
. . .
DDD is well suited to cases where it’s worth the price
Domain is huge and/or complex
Maintainability is critical
Efficiency is critical
Beware “à la carte” application of DDD
DDD is a global approach
→ most design rules are inter-dependent
Applying only parts of DDD might just get things harder but with
small benefits
If you still choose to do so, fine, but do not say you are doing DDD
Do you have questions?
Appendix: references
Eric Evans, Domain-Driven Design: Tackling Complexity in the
Heart of Software, 2003
Vaughn Vernon, Implementing Domain-Driven Design, 2013

More Related Content

PPT
Domain Driven Design Demonstrated
Alan Christensen
 
PDF
Refactoring for Domain Driven Design
David Berliner
 
PDF
Amazon AWS - a quick review
Geeks Anonymes
 
KEY
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
PPT
Domain Driven Design (DDD)
Tom Kocjan
 
PPTX
Domain driven design
its_skm
 
PPTX
Domain driven design
Mustafa Dağdelen
 
PPTX
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 
Domain Driven Design Demonstrated
Alan Christensen
 
Refactoring for Domain Driven Design
David Berliner
 
Amazon AWS - a quick review
Geeks Anonymes
 
ZendCon 2011 UnCon Domain-Driven Design
Bradley Holt
 
Domain Driven Design (DDD)
Tom Kocjan
 
Domain driven design
its_skm
 
Domain driven design
Mustafa Dağdelen
 
A Practical Guide to Domain Driven Design: Presentation Slides
thinkddd
 

What's hot (20)

PDF
Modelling a complex domain with Domain-Driven Design
Naeem Sarfraz
 
PPTX
Domain Driven Design Quickly
Mariam Hakobyan
 
PPTX
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan
 
PPTX
Domain Driven Design
Nader Albert
 
PPTX
Domain Driven Design Introduction
wojtek_s
 
PDF
Domain driven design and model driven development
Dmitry Geyzersky
 
PDF
Domain Driven Design and Hexagonal Architecture
Crishantha Nanayakkara
 
PPTX
Domain Driven Design - DDDSydney 2011
thinkddd
 
PDF
DDD Basics - Context mapping
Stijn Volders
 
PPTX
Domain Driven Design: Zero to Hero
Fabrício Rissetto
 
PDF
Domain-Driven Design Basics
Mathias Verraes
 
PDF
Domain-Driven Design (Artur Trosin Product Stream)
IT Arena
 
PDF
Introduction to Domain Driven Design
Christos Tsakostas
 
PPTX
Domain Driven Design & Hexagonal Architecture
Can Pekdemir
 
PDF
Domain Driven Design - Distillation - Chapter 15
Mark Windholtz
 
PDF
Domain Driven Design
Harsh Jegadeesan
 
PPTX
شرح Domain Driven Design بالعربي
Mohamed Galal
 
PDF
Domain Driven Design Development Spring Portfolio
Srini Penchikala
 
PPTX
How to Implement Domain Driven Design in Real Life SDLC
Abdul Karim
 
PDF
Domain Driven Design - Building Blocks
Mark Windholtz
 
Modelling a complex domain with Domain-Driven Design
Naeem Sarfraz
 
Domain Driven Design Quickly
Mariam Hakobyan
 
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan
 
Domain Driven Design
Nader Albert
 
Domain Driven Design Introduction
wojtek_s
 
Domain driven design and model driven development
Dmitry Geyzersky
 
Domain Driven Design and Hexagonal Architecture
Crishantha Nanayakkara
 
Domain Driven Design - DDDSydney 2011
thinkddd
 
DDD Basics - Context mapping
Stijn Volders
 
Domain Driven Design: Zero to Hero
Fabrício Rissetto
 
Domain-Driven Design Basics
Mathias Verraes
 
Domain-Driven Design (Artur Trosin Product Stream)
IT Arena
 
Introduction to Domain Driven Design
Christos Tsakostas
 
Domain Driven Design & Hexagonal Architecture
Can Pekdemir
 
Domain Driven Design - Distillation - Chapter 15
Mark Windholtz
 
Domain Driven Design
Harsh Jegadeesan
 
شرح Domain Driven Design بالعربي
Mohamed Galal
 
Domain Driven Design Development Spring Portfolio
Srini Penchikala
 
How to Implement Domain Driven Design in Real Life SDLC
Abdul Karim
 
Domain Driven Design - Building Blocks
Mark Windholtz
 
Ad

Similar to Domain-Driven Design (20)

PDF
Introduction to Domain driven design
Muhammad Ali
 
PPTX
Domain Driven Design
Muhammad Ali
 
PDF
D2 domain driven-design
Arnaud Bouchez
 
PDF
Domain Driven Design
Mojammel Haque
 
PPTX
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Mizanur Sarker
 
PPTX
Domain Driven Design
Ryan Riley
 
PPTX
Domain Driven Design
Hannah Farrugia
 
PPTX
Designing DDD Aggregates
Andrew McCaughan
 
PPTX
Introduction to DDD
Eduards Sizovs
 
PPTX
Domain Driven Design
Lalit Kale
 
PPTX
Software Development: Beyond Training wheels
Naveenkumar Muguda
 
PDF
Domain driven design: a gentle introduction
Asher Sterkin
 
PPT
Why do complex software application projects drag?
Stephen Erdman
 
PPT
Domain driven design
Yura Taras
 
PPTX
Domain Driven Design
Up2 Technology
 
PPTX
Up to speed in domain driven design
Rick van der Arend
 
PPTX
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh ...
Russell Beggs
 
PPTX
Intro to Domain Driven Design
Yaniv Preiss
 
PPT
Importance Of Being Driven
Antonio Terreno
 
PDF
DDD - 2 - Domain Driven Design: Tactical design.pdf
Eleonora Ciceri
 
Introduction to Domain driven design
Muhammad Ali
 
Domain Driven Design
Muhammad Ali
 
D2 domain driven-design
Arnaud Bouchez
 
Domain Driven Design
Mojammel Haque
 
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Mizanur Sarker
 
Domain Driven Design
Ryan Riley
 
Domain Driven Design
Hannah Farrugia
 
Designing DDD Aggregates
Andrew McCaughan
 
Introduction to DDD
Eduards Sizovs
 
Domain Driven Design
Lalit Kale
 
Software Development: Beyond Training wheels
Naveenkumar Muguda
 
Domain driven design: a gentle introduction
Asher Sterkin
 
Why do complex software application projects drag?
Stephen Erdman
 
Domain driven design
Yura Taras
 
Domain Driven Design
Up2 Technology
 
Up to speed in domain driven design
Rick van der Arend
 
Domain Driven Design Belfast Meetup - Overview, Lessons and Examples by Josh ...
Russell Beggs
 
Intro to Domain Driven Design
Yaniv Preiss
 
Importance Of Being Driven
Antonio Terreno
 
DDD - 2 - Domain Driven Design: Tactical design.pdf
Eleonora Ciceri
 
Ad

More from Geeks Anonymes (20)

PDF
Programmer sous Unreal Engine
Geeks Anonymes
 
PDF
Implémentation efficace et durable de processus métiers complexes
Geeks Anonymes
 
PDF
Managing Open Source Licenses (Geeks Anonymes)
Geeks Anonymes
 
PDF
Reprendre le contrôle de ses données
Geeks Anonymes
 
PDF
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
PDF
Le rôle du testeur et le Blackbox testing
Geeks Anonymes
 
PDF
Kubernetes
Geeks Anonymes
 
PDF
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
Geeks Anonymes
 
PDF
191121 philippe teuwen cryptographie et attaques materielles
Geeks Anonymes
 
PDF
"Surfez couverts !" - Conseils de Cyber securité
Geeks Anonymes
 
PDF
Introduction au développement mobile - développer une application iOS et Andr...
Geeks Anonymes
 
PDF
Le langage rust
Geeks Anonymes
 
PDF
Test your code
Geeks Anonymes
 
PDF
Intelligence artificielle et propriété intellectuelle
Geeks Anonymes
 
PDF
Pour une histoire plophonique du jeu video
Geeks Anonymes
 
PDF
Become Rick and famous, thanks to Open Source
Geeks Anonymes
 
PDF
Reconnaissance vocale et création artistique
Geeks Anonymes
 
PDF
Natural Language Processing
Geeks Anonymes
 
PDF
Sécurité, GDPR : vos données ont de la valeur
Geeks Anonymes
 
PDF
Modern sql
Geeks Anonymes
 
Programmer sous Unreal Engine
Geeks Anonymes
 
Implémentation efficace et durable de processus métiers complexes
Geeks Anonymes
 
Managing Open Source Licenses (Geeks Anonymes)
Geeks Anonymes
 
Reprendre le contrôle de ses données
Geeks Anonymes
 
Geeks Anonymes - Le langage Go
Geeks Anonymes
 
Le rôle du testeur et le Blackbox testing
Geeks Anonymes
 
Kubernetes
Geeks Anonymes
 
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
Geeks Anonymes
 
191121 philippe teuwen cryptographie et attaques materielles
Geeks Anonymes
 
"Surfez couverts !" - Conseils de Cyber securité
Geeks Anonymes
 
Introduction au développement mobile - développer une application iOS et Andr...
Geeks Anonymes
 
Le langage rust
Geeks Anonymes
 
Test your code
Geeks Anonymes
 
Intelligence artificielle et propriété intellectuelle
Geeks Anonymes
 
Pour une histoire plophonique du jeu video
Geeks Anonymes
 
Become Rick and famous, thanks to Open Source
Geeks Anonymes
 
Reconnaissance vocale et création artistique
Geeks Anonymes
 
Natural Language Processing
Geeks Anonymes
 
Sécurité, GDPR : vos données ont de la valeur
Geeks Anonymes
 
Modern sql
Geeks Anonymes
 

Recently uploaded (20)

PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PPTX
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
oapresentation.pptx
mehatdhavalrajubhai
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Hironori Washizaki
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
Presentation about variables and constant.pptx
safalsingh810
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
GALILEO CRS SYSTEM | GALILEO TRAVEL SOFTWARE
philipnathen82
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 

Domain-Driven Design

  • 1. Domain-Driven Design Focus on Knowledge, Efficiency and Maintainability Gérard Dethier1 1 Guardis / ComodIT http://www.comodit.com November 10th 2017 / Geeks Anonymes Liège
  • 2. Most IT systems consist in the implementation of a set of processes For instance, a company selling failure-prone products to coyotes: registration of a new client selling billing . . .
  • 3. Many implemented processes share the same structure Read some stuff from a database Modify parts of retrieved information while enforcing some rules Save the modified parts into the database
  • 4. While structure is simple, details can be complex When selling an Item to a Client, first check that there are enough Units available. If it’s the case, remove the Item from the Stock. If the number of Units in Stock goes below a given Threshold, the production of new Units should be triggered. Also, a Line should be added to the last Invoice not yet emitted. Finally, as soon as the Item is shipped, an e-mail should be sent to the Coyote. – An ACME domain expert
  • 5. Details may change in time Agile project management implies ever changing requirements The domain is evolving
  • 6. Domain experts and developers are not talking the same language Domain experts are talking about clients, units, stock, invoices, . . . Developers are talking about tables, records, objects, classes, relations, transactions. . . . . . and that’s perfectly fine (both languages are the most efficient when used in their context)!
  • 7. A common language is needed Understood by both domain experts and developers Precise Flexible Scalable in domain complexity
  • 8. The number of processes executed per time unit can be large For example, ACME faces: A growth in client base → many registrations many orders many invoices . . .
  • 9. Slow execution has a cost For example: Less registrations means less clients Slow invoicing has a bad impact on cash flow Slow client support might lead to clients leaving Note that the cost is not necessarily money
  • 10. Processes execution time must be low Implementation must be: Efficient Scalable
  • 11. Developers team evolves Developers might leave → potential loss of knowledge Team might grow to better respond to change → collaboration between developers becomes more complex (knowledge exchange, collisions in code changes. . . )
  • 12. Domain-Driven Design (DDD) is a framework addressing all those concerns Provides a meta-language for domain experts and developers easing the definition of a common language Includes the domain description in the code Defines design rules promoting flexible, efficient and scalable code, as well as improving collaboration between developers
  • 15. DDD defines a meta-language that can be used to develop a common language between domain experts and developers The meta-language looks like other well known “languages” (OOP, ER model) but is more abstract The Ubiquitous Language defines the vocabulary that domain experts and developers will use in their communication and in the code 10 design element types are available
  • 16. The Value Object (VO) has a state that does not evolve in time It has no identity and is only defined by its value It’s state is immutable It can have a behavior (it’s a good practice to put as much knowledge as possible in VOs) Examples: contact name, e-mail address, invoice number, . . .
  • 17. The Entity has a life cycle and an identity Its state may evolve over time It is uniquely identified by a key It’s state is, in general, made of a set of VOs It may reference other Entities
  • 18. The Aggregate defines a group of tightly coupled Entities One single Entity has the role of Aggregate Root it’s identity is the Aggregate’s identity it acts as an entry point to Aggregate’s behavior A set of invariants applies to the Entities part of the Aggregate No reference can point to any Entity of an Aggregate except the Aggregate Root
  • 19. Aggregates are built using Factories A Factory is stateless Built Aggregates have all their invariants fulfilled
  • 20. Aggregates are stored using Repositories A Repository is stateless Repositories expose a collection-like interface to perform CRUD operations Repositories hide the details of Aggregates’ storage
  • 21. A behavior not finding its place in any of previous elements is put in a Service A Service is stateless (Repositories and Factories are particular cases of Services) The choice of putting behavior in a Service rather than in a VO, Entity, Repository or Factory must be driven by the domain
  • 22. Modules allow to organize a domain when the number of elements grows The only purpose is organization No behavior No state
  • 23. When sub-domains are identified, they can be mapped to separate Bounded Contexts A Bounded Context defines a bounday in which a concept has a unique definition The same concept can appear in different Bounded Contexts but with varying definitions Bounded Contexts generally map to separate pieces of a system that model a given domain
  • 24. The Context Map shows the way Bounded Contexts are linked A link between 2 Bounded Contexts means they share related concepts Links can be annotated with the related concepts
  • 25. Only one Aggregate can be updated per transaction The Aggregate Root is acting as the “lock” At the end of the transaction, all invariants must be true
  • 26. Domain Events allow consistency rules spanning several Aggregates The update of one Aggregate triggers the publication of a Domain Event The Domain Event consumption implies the update of another Aggregate in another transaction After a sequence of transactions, all invariants are verified This is called Eventual Consistency
  • 27. Design elements can be categorized Stateful Behavioral Stuctural Value Object • • Entity • • Aggregate • Factory • Repository • Service • Module • Bounded Context • Context Map • Domain Event •
  • 29. Information is spread among elements with varying precision
  • 30. The structure of the model makes search efficient for everybody Tree search → O(logn) Domain experts and developers understand the model (they built it together!) The type of design elements tells if one might find a given type of information or not (state / behavior / structure)
  • 31. Deepening of the model does not get crippled by existing complexity . . . if information is evenly spread across leaves → VOs and Entities are the best places to store information It is then possible to focus on small pieces of the domain that need to be deepened
  • 33. Domain experts are generally open to delay the fulfillment of some constraints Acceptable delays may vary between a couple of seconds and days! Eventual Consistency can therefore be used in a lot of situations, in particular when fast response time is needed
  • 34. Small Aggregates are desirable Smaller (in terms of number of elements) Aggregates → shorter transactions Short transactions → improved scalability → reduced risk of conflict Perceived execution time for a process → short as only first step is blocking (following steps run in background)
  • 36. The model is documented by the code Discussions between domain experts and developers can be put in the context of actual code as both share a Ubiquitous Language No risk of stale external documentation obfuscating the model A domain expert is actually able to help a developer understand its own code!
  • 37. Clear separation of concerns allows parallel improvement of the model Several teams can work in parallel on separate Bounded Contexts Inside of the same Bounded Context, work can be planned on separate Aggregates Risk of conflicting changes is reduced
  • 38. Weak coupling of Aggregates makes code flexible Splitting a code base is easier Risk of “shotgun sugery” when refactoring is reduced
  • 39. Strong coupling inside of Aggregates makes code robust Most important invariants are implemented in a highly controlled environment Strong coupling inside of an Aggregate makes detection of issues in case of divergence in a sub-component faster
  • 40. The size Aggregates is a trade-off. . . The bigger, the more robust The smaller, the more efficient
  • 41. . . . but might also be driven by other requirements Domain experts might not agree to subdivide some Aggregates because it may not make sense Reminder: an Entity inside of an Aggregate which is not the Aggregate Root cannot be referenced from outside of the Aggregate → if a reference is needed to an Entity, it must be an Aggregate Root
  • 43. DDD is a powerful software design methodology Allowing a deep understanding of the domain by both experts and developers Promoting efficiency while allowing to preseve robustness Improving the maintainability of the code base
  • 44. It is often considered as “hard” Differences between design elements is sometimes subtel and badly understood Not concrete enough for developers Too abstract for domain experts In practice, a lot of technical details have to be solved Keeping domain model clean Transport of Domain Events in a distributed environment Handling of failed Domain Event consumption Handling of duplicate Domain Event consumptions . . .
  • 45. DDD is well suited to cases where it’s worth the price Domain is huge and/or complex Maintainability is critical Efficiency is critical
  • 46. Beware “à la carte” application of DDD DDD is a global approach → most design rules are inter-dependent Applying only parts of DDD might just get things harder but with small benefits If you still choose to do so, fine, but do not say you are doing DDD
  • 47. Do you have questions?
  • 48. Appendix: references Eric Evans, Domain-Driven Design: Tackling Complexity in the Heart of Software, 2003 Vaughn Vernon, Implementing Domain-Driven Design, 2013