SlideShare une entreprise Scribd logo
1  sur  44
Jak Charlton jak@thinkddd.com www.thinkddd.com Readify www.readify.net
Practical Domain Driven Design Message Based Architecture and CQRS
Domain Driven Design IS An architectural methodology for evolving a software system  that closely aligns  to business requirements
Domain Driven Design IS NOT A silver bullet A panacea for all your troubles An easy path to follow Always the best solution And most importantly, it is not focused on the How, but the What and Why
Where Are We Going?
The Domain Vision Statement A shared understanding of what it is you are actually trying to create Should be brief, written in clear English and understood by business and tech people alike Should be factual, realistic, honest Should avoid superlatives and marketing speak Should avoid technical and implementation details
Domain = Sphere of Activity?
Domain A Domain is a Sphere of Knowledge, Influenceor Activity A Domain is represented by the Ubiquitous Language A Domain encapsulates a Domain Model A Domain lives within a Bounded Context
The Ubiquitous Language Human languages are Lossy Abstractions A major reason for failure of software projects is a failure of people, the failure to communicate The Ubiquitous Language is a shared language between the business and the development teams The UL comes from the business, and is enriched by the development teams
Domain Experts Domain Experts are the primary point of contact the development teams have with the business They are the Experts on their part of the business, not just users of the system They should have deep knowledge of the subject Domain
Looks Pretty Unique To Me
Entities Entities are the “things” within your Model An Entity is defined by being unique, and uniquely identifiable Entities have behaviour
You Can’t Tell One From Another
Value Objects Value Objects are the “things” within your model that have no uniqueness They are equal in all ways to another Value Object if all their properties match Value Objects are interchangeable
How Can We Make Sense?
Domain Model A Domain Model is a representation of the relationships between the Entities and Value Objects in your Domain It may look similar to UML or a class relationship diagram, but it is not one The Domain Model should be recognisable and understandable by the business
That’s a Lot of Bits
Aggregates “An aggregate is a collection of items that are gathered together to form a total quantity” - Wikipedia An Aggregate Root is the root item containing a number of parts that form a whole An AR is more likely to match a Use Case than any model structure
Everyone Loves an Event!
Domain Events The “3rd Thing” in DDD Like all events, notification that “something happened” They are in the past tense, and should be named accordingly Closely aligned to your Domain Model Will probably be handled by your messaging layer
Bounded Contexts When you have multiple models you should consider Bounded Contexts Each BC is a self contained “mini application” containing it’s own model, persistence and code base Within a BC, everything should be strictly consistent To map between BCs you use a Context Map
Transformer Domain Vehicle Domain
Context Maps A Context Map provides a clearly defined relationship between Bounded Contexts and the interactions between their Domain Models A Context Map may be represented in many forms, but it comprises the rules for how to turn A into B
Persistence Ignorance Subtitled “There Is No Database”  DDD uses the Repository pattern to create Persistence Ignorance A Repository represents itself as an in-memory list of items Repositories are specific to Aggregate Roots, not to Entities
Anti-Corruption Layers An Anti-Corruption Layer is a method to isolate two systems, allowing systems to be integrated without knowledge of each other An ACL presents a Facade to both systems, defined in terms of their specific models ACLs maintain the integrity of a Domain
Factors For Success of DDD Your domain is not trivial You have access to Domain Experts You have an iterative process You have a skilled and motivated team
Where Does DDD Work Best? Domain Driven Design is  a way of dealing with complexity DDD is ideally suited to Behaviour Centric SystemsnotData Centric systems
Messaging Architectures DDD is ideally suited to Message Based Architectures DDD is ideally suited to Commands and Events DDD without Commands and Events is going to be a lot of hard work DDD is ideally suited to providing multiple autonomous systems that are loosely coupled
CAP Theorem Consistency: The client perceives that a set of operations has occurred all at once. Availability: Every operation must terminate in an intended response. Partition tolerance: Operations will complete, even if individual components are unavailable. You cannot have all three
ACID Atomicity, Consistent, Isolation, Durability Gives you Consistency and Availability Sacrifices Partition Tolerance Meaning: ACID systems are hard and expensive to scale
BASE Basically Available, Soft state, Eventually consistent Gives you Availability and Partition Tolerance Sacrifices Consistency Meaning BASE systems can scale easily and are very fault tolerant
BASE at a Database Level Most RDBMS databases are ACID Most NoSQL databases are BASE The largest expense in database systems is in fault tolerance and scaling BASE databases scale massively and cheaply BASE databases are highly fault tolerant
BASE at an Architectural Level Latency is the biggest constraint on architecture Unless you have pessimistic locking, all data is stale Most mistakes in developer code are around consistency vs. latency The main cause of rigidity and fragility in systems is due to trying to maintain consistency Command Query Responsibility Segregation gives us BASE at an architectural level
Command Query Responsibility Segregation (CQRS) Bertrand Meyer principle of CQS:every method should either be a command that performs an action, or a query that returns data to the caller At an architectural level this means:either issue commands, or issue queries, but never both And, query from a separate source from your domain commands
CQRS in a Picture Client Command Domain Event Handlers Queries (synchronous no bus) Event Handlers Publish Persist Update Domain Persistence Read Model
CQRS in a Simpler Picture Domain Read Model Events Commands DTOs Client
CQRS Useful Only for Scaling? CQRS gives us hugely simplified Domain persistence and leaves the Domain free of orthogonal concerns CQRS lets us focus on real Domain logic CQRS gives us optimised reporting and querying capability CQRS removes a large amount of the effort involved in dealing with inconsistent systems pretending to be consistent CQRS has real business benefits beyond scaling
Questions? Jak Charlton jak@thinkddd.com www.thinkddd.com Readify www.readify.net

Contenu connexe

En vedette

Domain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioDomain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioSrini Penchikala
 
Microservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationMicroservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationKevin Webber
 
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...Alberto Brandolini
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design IntroductionTung Nguyen Thanh
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcingManel Sellés
 
Introdução ao Domain-Driven Design
Introdução ao Domain-Driven DesignIntrodução ao Domain-Driven Design
Introdução ao Domain-Driven DesignAndré Borgonovo
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignLaunchAny
 
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraA Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraOpenCredo
 
Projections explained
Projections explainedProjections explained
Projections explainedYves Reynhout
 
Greg Young on Architectural Innovation: Eventing, Event Sourcing
Greg Young on Architectural Innovation: Eventing, Event SourcingGreg Young on Architectural Innovation: Eventing, Event Sourcing
Greg Young on Architectural Innovation: Eventing, Event SourcingSkills Matter
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event SourcingMike Bild
 
Developing event-driven microservices with event sourcing and CQRS (phillyete)
Developing event-driven microservices with event sourcing and CQRS (phillyete)Developing event-driven microservices with event sourcing and CQRS (phillyete)
Developing event-driven microservices with event sourcing and CQRS (phillyete)Chris Richardson
 
Adição de ácido clorídrico no meio reacional
Adição de ácido clorídrico no meio reacionalAdição de ácido clorídrico no meio reacional
Adição de ácido clorídrico no meio reacionalAnderson Lima
 
Most Hilarious Moments of FIFA 2014
Most Hilarious Moments of FIFA 2014Most Hilarious Moments of FIFA 2014
Most Hilarious Moments of FIFA 2014ixigo.com
 
交點高雄vol.7 - 安蓉 - 傳說中的文化差異
交點高雄vol.7 - 安蓉 - 傳說中的文化差異交點高雄vol.7 - 安蓉 - 傳說中的文化差異
交點高雄vol.7 - 安蓉 - 傳說中的文化差異交點
 

En vedette (17)

Domain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring PortfolioDomain Driven Design Development Spring Portfolio
Domain Driven Design Development Spring Portfolio
 
DDD Dirty Harry style
DDD Dirty Harry styleDDD Dirty Harry style
DDD Dirty Harry style
 
Microservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationMicroservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time Organization
 
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...
Loosely Coupled Complexity - Unleash the power of your Domain Model with Comm...
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
When cqrs meets event sourcing
When cqrs meets event sourcingWhen cqrs meets event sourcing
When cqrs meets event sourcing
 
Introdução ao Domain-Driven Design
Introdução ao Domain-Driven DesignIntrodução ao Domain-Driven Design
Introdução ao Domain-Driven Design
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven Design
 
Model storming
Model stormingModel storming
Model storming
 
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraA Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
 
Projections explained
Projections explainedProjections explained
Projections explained
 
Greg Young on Architectural Innovation: Eventing, Event Sourcing
Greg Young on Architectural Innovation: Eventing, Event SourcingGreg Young on Architectural Innovation: Eventing, Event Sourcing
Greg Young on Architectural Innovation: Eventing, Event Sourcing
 
CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
Developing event-driven microservices with event sourcing and CQRS (phillyete)
Developing event-driven microservices with event sourcing and CQRS (phillyete)Developing event-driven microservices with event sourcing and CQRS (phillyete)
Developing event-driven microservices with event sourcing and CQRS (phillyete)
 
Adição de ácido clorídrico no meio reacional
Adição de ácido clorídrico no meio reacionalAdição de ácido clorídrico no meio reacional
Adição de ácido clorídrico no meio reacional
 
Most Hilarious Moments of FIFA 2014
Most Hilarious Moments of FIFA 2014Most Hilarious Moments of FIFA 2014
Most Hilarious Moments of FIFA 2014
 
交點高雄vol.7 - 安蓉 - 傳說中的文化差異
交點高雄vol.7 - 安蓉 - 傳說中的文化差異交點高雄vol.7 - 安蓉 - 傳說中的文化差異
交點高雄vol.7 - 安蓉 - 傳說中的文化差異
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 

Practical Domain Driven Design, CQRS and Messaging Architectures

  • 1. Jak Charlton jak@thinkddd.com www.thinkddd.com Readify www.readify.net
  • 2. Practical Domain Driven Design Message Based Architecture and CQRS
  • 3. Domain Driven Design IS An architectural methodology for evolving a software system that closely aligns to business requirements
  • 4. Domain Driven Design IS NOT A silver bullet A panacea for all your troubles An easy path to follow Always the best solution And most importantly, it is not focused on the How, but the What and Why
  • 5. Where Are We Going?
  • 6. The Domain Vision Statement A shared understanding of what it is you are actually trying to create Should be brief, written in clear English and understood by business and tech people alike Should be factual, realistic, honest Should avoid superlatives and marketing speak Should avoid technical and implementation details
  • 7. Domain = Sphere of Activity?
  • 8. Domain A Domain is a Sphere of Knowledge, Influenceor Activity A Domain is represented by the Ubiquitous Language A Domain encapsulates a Domain Model A Domain lives within a Bounded Context
  • 9.
  • 10. The Ubiquitous Language Human languages are Lossy Abstractions A major reason for failure of software projects is a failure of people, the failure to communicate The Ubiquitous Language is a shared language between the business and the development teams The UL comes from the business, and is enriched by the development teams
  • 11.
  • 12. Domain Experts Domain Experts are the primary point of contact the development teams have with the business They are the Experts on their part of the business, not just users of the system They should have deep knowledge of the subject Domain
  • 14. Entities Entities are the “things” within your Model An Entity is defined by being unique, and uniquely identifiable Entities have behaviour
  • 15. You Can’t Tell One From Another
  • 16. Value Objects Value Objects are the “things” within your model that have no uniqueness They are equal in all ways to another Value Object if all their properties match Value Objects are interchangeable
  • 17. How Can We Make Sense?
  • 18. Domain Model A Domain Model is a representation of the relationships between the Entities and Value Objects in your Domain It may look similar to UML or a class relationship diagram, but it is not one The Domain Model should be recognisable and understandable by the business
  • 19. That’s a Lot of Bits
  • 20. Aggregates “An aggregate is a collection of items that are gathered together to form a total quantity” - Wikipedia An Aggregate Root is the root item containing a number of parts that form a whole An AR is more likely to match a Use Case than any model structure
  • 22. Domain Events The “3rd Thing” in DDD Like all events, notification that “something happened” They are in the past tense, and should be named accordingly Closely aligned to your Domain Model Will probably be handled by your messaging layer
  • 23.
  • 24. Bounded Contexts When you have multiple models you should consider Bounded Contexts Each BC is a self contained “mini application” containing it’s own model, persistence and code base Within a BC, everything should be strictly consistent To map between BCs you use a Context Map
  • 26. Context Maps A Context Map provides a clearly defined relationship between Bounded Contexts and the interactions between their Domain Models A Context Map may be represented in many forms, but it comprises the rules for how to turn A into B
  • 27.
  • 28. Persistence Ignorance Subtitled “There Is No Database”  DDD uses the Repository pattern to create Persistence Ignorance A Repository represents itself as an in-memory list of items Repositories are specific to Aggregate Roots, not to Entities
  • 29.
  • 30. Anti-Corruption Layers An Anti-Corruption Layer is a method to isolate two systems, allowing systems to be integrated without knowledge of each other An ACL presents a Facade to both systems, defined in terms of their specific models ACLs maintain the integrity of a Domain
  • 31.
  • 32. Factors For Success of DDD Your domain is not trivial You have access to Domain Experts You have an iterative process You have a skilled and motivated team
  • 33. Where Does DDD Work Best? Domain Driven Design is a way of dealing with complexity DDD is ideally suited to Behaviour Centric SystemsnotData Centric systems
  • 34. Messaging Architectures DDD is ideally suited to Message Based Architectures DDD is ideally suited to Commands and Events DDD without Commands and Events is going to be a lot of hard work DDD is ideally suited to providing multiple autonomous systems that are loosely coupled
  • 35. CAP Theorem Consistency: The client perceives that a set of operations has occurred all at once. Availability: Every operation must terminate in an intended response. Partition tolerance: Operations will complete, even if individual components are unavailable. You cannot have all three
  • 36. ACID Atomicity, Consistent, Isolation, Durability Gives you Consistency and Availability Sacrifices Partition Tolerance Meaning: ACID systems are hard and expensive to scale
  • 37. BASE Basically Available, Soft state, Eventually consistent Gives you Availability and Partition Tolerance Sacrifices Consistency Meaning BASE systems can scale easily and are very fault tolerant
  • 38. BASE at a Database Level Most RDBMS databases are ACID Most NoSQL databases are BASE The largest expense in database systems is in fault tolerance and scaling BASE databases scale massively and cheaply BASE databases are highly fault tolerant
  • 39. BASE at an Architectural Level Latency is the biggest constraint on architecture Unless you have pessimistic locking, all data is stale Most mistakes in developer code are around consistency vs. latency The main cause of rigidity and fragility in systems is due to trying to maintain consistency Command Query Responsibility Segregation gives us BASE at an architectural level
  • 40. Command Query Responsibility Segregation (CQRS) Bertrand Meyer principle of CQS:every method should either be a command that performs an action, or a query that returns data to the caller At an architectural level this means:either issue commands, or issue queries, but never both And, query from a separate source from your domain commands
  • 41. CQRS in a Picture Client Command Domain Event Handlers Queries (synchronous no bus) Event Handlers Publish Persist Update Domain Persistence Read Model
  • 42. CQRS in a Simpler Picture Domain Read Model Events Commands DTOs Client
  • 43. CQRS Useful Only for Scaling? CQRS gives us hugely simplified Domain persistence and leaves the Domain free of orthogonal concerns CQRS lets us focus on real Domain logic CQRS gives us optimised reporting and querying capability CQRS removes a large amount of the effort involved in dealing with inconsistent systems pretending to be consistent CQRS has real business benefits beyond scaling
  • 44. Questions? Jak Charlton jak@thinkddd.com www.thinkddd.com Readify www.readify.net