SlideShare a Scribd company logo
Domain Driven Design
Satish Mittal
VP Engineering
Practo
Motivation
Typical application development:
Requirements from business
Task breakdown
Jump to implementation
DB schema - tables and columns
Fast, we are a Startup!
Problems
1. Your project has the same functionality implemented in the same way or
different in different places?
2. You have more than one object for the same item?
3. You have objects that have properties that are not actually attributes of that
object?
4. You have no or very poor relationship among related items?
5. Looking at your objects it is not possible to understand what actually the
whole application is all about?
Problems
Bottom-up vs Top-down approach
Here-and-now vs big-picture
Do I understand the domain of the application?
Solution
Domain Driven Design (DDD)
Coined by Eric Evans
Wikipedia: Domain-driven design is not a technology or a methodology. DDD
provides a structure of practices and terminology for making design decisions
that focus and accelerate software projects dealing with complicated
domains.
Idea: Focus more on complexities intrinsic to core business domain
Domain
Wikipedia: A sphere of knowledge, influence, or activity. The subject area to
which the user applies a program is the domain of the software
Examples:
E-commerce
Professional network
Advertisement
Healthcare
...
What is a model?
It’s not just diagrams (UML, ER): views of model
Model is the set of concepts that we have chosen to implement in our software
Business differentiator
Pattern: Model-driven design
First build an of domain model that actually represents the problem domain
Then express that in code at all times
Change in domain <-> Change in code
Ubiquitous Language
All stakeholders should speak the same language
Product-developers
Developers-developers
The language must be business language, and not technical details
Language: Entity
A concept that has a unique identity within system
Two entities can only be same if their identity is identical
Typically persisted, mutable, status change
Examples:
Friend in Facebook
Item in shopping cart: SKU
News Article: URL
Language: Value Object
Represents a set of attributes
e.g. doors in a room, items in an order, profile details
Typically it has no unique identity of its own
It should be immutable
In some cases, Value Object might become an entity (when unique identity is
needed to invoke some action)
Example: last N SearchCriteria
Language: Value Object
E.g. money: int, double field in code?
How about various currencies: INR/USD?
Recommendation: Define unique class
Money m1 = new Money("GBP", 10);
Money m2 = new Money("GBP", 20);
Money m3 = m1.add(m2);
Typically immutable
Adding m1 to m2 doesn’t alter m1; returns m3
Language: Value Object
E.g. SocialSecurityNumber
E.g. MobilePhoneNumber
E.g. PatientRegistrationNumber
Perform common validations within each class: range check, syntax, format
Refactor duplicate implementations out of applications
Language: Module
Package or library or namespace
Collection of entities and Value Objects related to a context
Focus on having as much reusable modules amongst applications across
company
Language: Aggregate Roots
Entity relationship types: association, aggregation or composition
An aggregate root (AR) is an entity that composes other entities (as well as its
own Value Object) by composition.
Example:
Consult Question (AR) contains multiple Answers. However any Answer can’t exist without
Question
Aggregated entities are referenced only by the root (may be transitively), and
may not be referenced by any objects outside the aggregate.
Some entities are aggregate roots themselves (single node tree)
Language: Aggregate Roots
Identifying AR allows us to define the logical atomic unit of work
critical section of a transaction
AR is responsible for ensuring that all its child entities are always in consistent
state across operations
Example:
Order (AR) contains OrderItems; all OrderItems must be unique
Referential Integrity across ARs:
Appointment for a slot must be given only if Doctor is available that day
Language: Repository
Domain must be agnostic of persistence (MySQL, ES, Redis, FS..)
Repository is an abstraction over persistence layer
Returns collections of aggregate roots (typically meeting some criteria)
Repository is a domain level concept - represented via Interface
Actual implementations belong to Infrastructure layer
Dependency Injection
Domain Service: Represents core business actions, operations on Domain
Entities; manages business rules
Example: Appointment booking, medicine order
Application Service: Handles cross-cutting concerns like transactions, security
etc.
Infrastructure Service: Underlying tech implementation layer
Example: MySQL, SMS communicator, push notification
Language: Service Types
Language: Service Types
Layered architecture
Spectrum of granularity
Value Object < entity < aggregate < module < bounded context
Language: Bounded Context
BC: The functional boundary within which domain model make sense
Recommendation: Divide large application among multiple BCs
More modular
Separation of different concerns
Helps manage and enhance application in an efficient way
Each BC operates in a semi-autonomous fashion
Each BC owned by separate team: domain expert
Avoid BBOM (Big Ball of Mud): unstructured, duct-tape, sphagetti code
Bounded Context: Relationships
published language: the interacting BCs agree on a common language (e.g.
domain schema) by which they can interact with each other;
open host service: a BC specifies a protocol (e.g. RPC/RESTful web service)
by which any other BC can use its services;
shared kernel: two BCs use a common kernel of code (e.g. a library)
Bounded Context: Relationships
customer/supplier: one BC uses the services of another and is a stakeholder
(customer) of that other BC. As such it can influence the services provided by
that BC;
conformist: one BC uses the services of another but is not a stakeholder to that
other BC. As such it uses "as-is" (conforms to) the protocols or APIs provided
by that BC;
anti-corruption layer: one BC uses the services of another and is not a
stakeholder, but aims to minimize impact from changes in the BC it depends
on by introducing a set of adapters – an anti-corruption layer.
Domain driven design
Context Map
DDD recommends to draw Context Map to identify which BC do you depend
upon, and which BC depend upon you
Dependency graph amongst systems, with edges that capture the co-operation
level
Helps understand the inter-dependencies better
Helps streamline upstream model changes
Thanks!

More Related Content

PPT
Domain Driven Design (DDD)
PPTX
Introduction to DDD
PPSX
Domain Driven Design
PPTX
Domain Driven Design
PPTX
Domain Driven Design
PPTX
Domain Driven Design 101
PPTX
Domain Driven Design Introduction
PPTX
Domain Driven Design
Domain Driven Design (DDD)
Introduction to DDD
Domain Driven Design
Domain Driven Design
Domain Driven Design
Domain Driven Design 101
Domain Driven Design Introduction
Domain Driven Design

What's hot (20)

PPTX
Enterprise Software Architecture styles
PPT
Domain Driven Design Demonstrated
PPTX
Domain Driven Design(DDD) Presentation
PDF
Domain Driven Design
PDF
Kubernetes 101 - A Cluster Operating System
PDF
Introducing Clean Architecture
PDF
Scrum + bdd + ddd
PPTX
Api gateway in microservices
PPTX
Domain Driven Design - Strategic Patterns and Microservices
PPTX
Applying Domain-Driven Design to craft Rich Domain Models
PPTX
A Practical Guide to Domain Driven Design: Presentation Slides
PPTX
Domain Driven Design: Zero to Hero
PPTX
Domain driven design
PPTX
Domain driven design
PPTX
Kubernetes for Beginners: An Introductory Guide
PDF
Achieving CI/CD with Kubernetes
PDF
Introduction of Kubernetes - Trang Nguyen
PPTX
Introduction to Docker - 2017
PPTX
Clean architecture
PDF
Gitops: the kubernetes way
Enterprise Software Architecture styles
Domain Driven Design Demonstrated
Domain Driven Design(DDD) Presentation
Domain Driven Design
Kubernetes 101 - A Cluster Operating System
Introducing Clean Architecture
Scrum + bdd + ddd
Api gateway in microservices
Domain Driven Design - Strategic Patterns and Microservices
Applying Domain-Driven Design to craft Rich Domain Models
A Practical Guide to Domain Driven Design: Presentation Slides
Domain Driven Design: Zero to Hero
Domain driven design
Domain driven design
Kubernetes for Beginners: An Introductory Guide
Achieving CI/CD with Kubernetes
Introduction of Kubernetes - Trang Nguyen
Introduction to Docker - 2017
Clean architecture
Gitops: the kubernetes way
Ad

Viewers also liked (14)

PDF
Server-side Swift
PDF
Project Management in Digital Age
PPTX
詹姆士看天下 2017/02/13
PDF
Evolución del marketing educativo hasta el Inbound marketing. Marketing and S...
PDF
さくらのIoT Platformを使ってみよう ~OSC浜名湖編~
PPT
Contextual Theology
PPSX
JANUARY 2017 - Pictures of the day - Jan. 1 - Jan. 6
PDF
Eu coal stress_test_report_2017 WindSolar = More and More Coal (1)
PDF
999C1400_De NoraGWSBrochure_Sept15-EMAIL
PPTX
Idempotent filter with mule
PPT
BU On Campus presentation of Apr 19 2011
PPTX
EN2 Characteristics of prophecy 2 of 6
PDF
マーケティングオートメーション&Mauticとは(WordBench Nagoya 2017年2月勉強会)
PDF
Domain-driven design
Server-side Swift
Project Management in Digital Age
詹姆士看天下 2017/02/13
Evolución del marketing educativo hasta el Inbound marketing. Marketing and S...
さくらのIoT Platformを使ってみよう ~OSC浜名湖編~
Contextual Theology
JANUARY 2017 - Pictures of the day - Jan. 1 - Jan. 6
Eu coal stress_test_report_2017 WindSolar = More and More Coal (1)
999C1400_De NoraGWSBrochure_Sept15-EMAIL
Idempotent filter with mule
BU On Campus presentation of Apr 19 2011
EN2 Characteristics of prophecy 2 of 6
マーケティングオートメーション&Mauticとは(WordBench Nagoya 2017年2月勉強会)
Domain-driven design
Ad

Similar to Domain driven design (20)

PDF
ddd.pdf
PDF
Domain Driven Design
PDF
Domain-Driven Design
PDF
Domain driven design and model driven development
PPTX
Domain Driven Design Quickly
PDF
2011-05-22 Domain Driven Design
PDF
2011-05-22 Domain Driven Design
PPTX
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
PDF
Domain driven design: a gentle introduction
PPTX
Domain Driven Design
PPTX
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
PPT
Domain driven design
PPTX
Domain driven design
PDF
Introduction to Domain driven design
PPTX
Schibsted Spain - Day 1 - DDD Course
PPTX
Arch CoP - Domain Driven Design.pptx
PDF
Beyond MVC: from Model to Domain
PDF
Domain Driven Design
PPTX
Implementing DDD with C#
PPTX
Introducing domain driven design - dogfood con 2018
ddd.pdf
Domain Driven Design
Domain-Driven Design
Domain driven design and model driven development
Domain Driven Design Quickly
2011-05-22 Domain Driven Design
2011-05-22 Domain Driven Design
Seminar - Scalable Enterprise Application Development Using DDD and CQRS
Domain driven design: a gentle introduction
Domain Driven Design
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Domain driven design
Domain driven design
Introduction to Domain driven design
Schibsted Spain - Day 1 - DDD Course
Arch CoP - Domain Driven Design.pptx
Beyond MVC: from Model to Domain
Domain Driven Design
Implementing DDD with C#
Introducing domain driven design - dogfood con 2018

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PDF
Modernizing your data center with Dell and AMD
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
A Presentation on Artificial Intelligence
DOCX
The AUB Centre for AI in Media Proposal.docx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
Modernizing your data center with Dell and AMD
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Network Security Unit 5.pdf for BCA BBA.
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A Presentation on Artificial Intelligence
The AUB Centre for AI in Media Proposal.docx

Domain driven design

  • 1. Domain Driven Design Satish Mittal VP Engineering Practo
  • 2. Motivation Typical application development: Requirements from business Task breakdown Jump to implementation DB schema - tables and columns Fast, we are a Startup!
  • 3. Problems 1. Your project has the same functionality implemented in the same way or different in different places? 2. You have more than one object for the same item? 3. You have objects that have properties that are not actually attributes of that object? 4. You have no or very poor relationship among related items? 5. Looking at your objects it is not possible to understand what actually the whole application is all about?
  • 4. Problems Bottom-up vs Top-down approach Here-and-now vs big-picture Do I understand the domain of the application?
  • 5. Solution Domain Driven Design (DDD) Coined by Eric Evans Wikipedia: Domain-driven design is not a technology or a methodology. DDD provides a structure of practices and terminology for making design decisions that focus and accelerate software projects dealing with complicated domains. Idea: Focus more on complexities intrinsic to core business domain
  • 6. Domain Wikipedia: A sphere of knowledge, influence, or activity. The subject area to which the user applies a program is the domain of the software Examples: E-commerce Professional network Advertisement Healthcare ...
  • 7. What is a model? It’s not just diagrams (UML, ER): views of model Model is the set of concepts that we have chosen to implement in our software Business differentiator
  • 8. Pattern: Model-driven design First build an of domain model that actually represents the problem domain Then express that in code at all times Change in domain <-> Change in code
  • 9. Ubiquitous Language All stakeholders should speak the same language Product-developers Developers-developers The language must be business language, and not technical details
  • 10. Language: Entity A concept that has a unique identity within system Two entities can only be same if their identity is identical Typically persisted, mutable, status change Examples: Friend in Facebook Item in shopping cart: SKU News Article: URL
  • 11. Language: Value Object Represents a set of attributes e.g. doors in a room, items in an order, profile details Typically it has no unique identity of its own It should be immutable In some cases, Value Object might become an entity (when unique identity is needed to invoke some action) Example: last N SearchCriteria
  • 12. Language: Value Object E.g. money: int, double field in code? How about various currencies: INR/USD? Recommendation: Define unique class Money m1 = new Money("GBP", 10); Money m2 = new Money("GBP", 20); Money m3 = m1.add(m2); Typically immutable Adding m1 to m2 doesn’t alter m1; returns m3
  • 13. Language: Value Object E.g. SocialSecurityNumber E.g. MobilePhoneNumber E.g. PatientRegistrationNumber Perform common validations within each class: range check, syntax, format Refactor duplicate implementations out of applications
  • 14. Language: Module Package or library or namespace Collection of entities and Value Objects related to a context Focus on having as much reusable modules amongst applications across company
  • 15. Language: Aggregate Roots Entity relationship types: association, aggregation or composition An aggregate root (AR) is an entity that composes other entities (as well as its own Value Object) by composition. Example: Consult Question (AR) contains multiple Answers. However any Answer can’t exist without Question Aggregated entities are referenced only by the root (may be transitively), and may not be referenced by any objects outside the aggregate. Some entities are aggregate roots themselves (single node tree)
  • 16. Language: Aggregate Roots Identifying AR allows us to define the logical atomic unit of work critical section of a transaction AR is responsible for ensuring that all its child entities are always in consistent state across operations Example: Order (AR) contains OrderItems; all OrderItems must be unique Referential Integrity across ARs: Appointment for a slot must be given only if Doctor is available that day
  • 17. Language: Repository Domain must be agnostic of persistence (MySQL, ES, Redis, FS..) Repository is an abstraction over persistence layer Returns collections of aggregate roots (typically meeting some criteria) Repository is a domain level concept - represented via Interface Actual implementations belong to Infrastructure layer Dependency Injection
  • 18. Domain Service: Represents core business actions, operations on Domain Entities; manages business rules Example: Appointment booking, medicine order Application Service: Handles cross-cutting concerns like transactions, security etc. Infrastructure Service: Underlying tech implementation layer Example: MySQL, SMS communicator, push notification Language: Service Types
  • 20. Spectrum of granularity Value Object < entity < aggregate < module < bounded context
  • 21. Language: Bounded Context BC: The functional boundary within which domain model make sense Recommendation: Divide large application among multiple BCs More modular Separation of different concerns Helps manage and enhance application in an efficient way Each BC operates in a semi-autonomous fashion Each BC owned by separate team: domain expert Avoid BBOM (Big Ball of Mud): unstructured, duct-tape, sphagetti code
  • 22. Bounded Context: Relationships published language: the interacting BCs agree on a common language (e.g. domain schema) by which they can interact with each other; open host service: a BC specifies a protocol (e.g. RPC/RESTful web service) by which any other BC can use its services; shared kernel: two BCs use a common kernel of code (e.g. a library)
  • 23. Bounded Context: Relationships customer/supplier: one BC uses the services of another and is a stakeholder (customer) of that other BC. As such it can influence the services provided by that BC; conformist: one BC uses the services of another but is not a stakeholder to that other BC. As such it uses "as-is" (conforms to) the protocols or APIs provided by that BC; anti-corruption layer: one BC uses the services of another and is not a stakeholder, but aims to minimize impact from changes in the BC it depends on by introducing a set of adapters – an anti-corruption layer.
  • 25. Context Map DDD recommends to draw Context Map to identify which BC do you depend upon, and which BC depend upon you Dependency graph amongst systems, with edges that capture the co-operation level Helps understand the inter-dependencies better Helps streamline upstream model changes