SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
From ddd
to DDD
An ongoing journey
Thibaud Desodt - @tsimbalar
What this is about
• Me, myself and I
• Code
• Architecture
• Learning process
Where it all started
E-commerce site
ASP.NET / C#
Back-office site
“classic” ASP / VbScript
Data
Tables
Stored Procedures
T-SQL
PRESENTATION
BUSINESS LOGIC
DATA
And it was …
• Not super pleasant
• VbScript
• T-SQL
• Fragile
• No automated tests
• Tight coupling
• Schema -> Stored Procs -> Website / admin site
… but it worked “well enough”!
• Customer value
• Happy customer
• Fast delivery of features
• Reasonable perf
• Easy to work on
• 1 feature ≈ 1 stored procedure
It worked well ... in that context
• Working alone on project
• Version 1 of the product
• Well-defined requirements
• Tight interactions with customer
• Simple domain
= ideal greenfield project
A few years later …
Similar approach, different context
A different context
• 40,000+ employees company
• 100s of developers spread across the globe
• Many different systems accessing the database(s)
This scripts that runs
every night
That excel sheet
nobody understands
Admin CRUD app
Quotation app
Data
800+ Tables
3000+ Stored Procedures
T-SQL
Customer-facing web appsB2B SOAP services
Internal Catalogue app
Reporting App
Bob running random
SQL queries
The Enterprise Database ™
Many issues
• Evolution is hard
• Testing is hard
• Versioning / collaboration is hard
• Performance is not great
the “solution” ….
• Team of 50 DBAs
• The “database” committee
• The “database” change process
• The “meta-database”
• Db replication
• Governance
Technical solutions
… to solve technical issues
… introduced because of technical decisions
… with no value to the users
= Accidental complexity
Moving away from database-driven
• Persistence is an implementation detail
• Focus on customer value
Relational DB, Document DB, Key-Value store, file …
Who cares ?
Business > Tech
App
PRESENTATION
DATA
BUSINESS LOGIC
PRESENTATION
DATA
BUSINESS LOGIC
Bringing the logic back to the code
Bringing the logic back to the code
• No more Stored Procedures
• ORM (Entity Framework in that case)
• Data-access code + Entities* generated from database
* Not quite
Status
That’s better !
• No more business logic in the DB
• Quite readable
Still a bit messy:
• Not testable
• Hard coupling
DATA
BUSINESS
LOGIC
Better layering
DATA
BUSINESS LOGIC
Better layering
Services
Repositories
+ Unit of Work Abstract away details of how
data is accessed
Orchestrate data-flow for a
given use-case
Repository
A “Service”
Status
Quite an improvement
• Decoupled
• Testable
• Easy to know where
functionality should live
• It worked fine initially
But … wait a minute …
Object graphs
When loading an
Order from DB …what
else should I load ?
- All the relationships ?
- Some of them, and leave some
unpopulated (null) ?
- Some of them, and use lazy-
loading ?
define Aggregates
Deliberately delimit clusters of objects that
live together and are loaded/stored together.
… keep them as small as possible
Object graphs
identify the Aggregate Root
The unique entry point to the graph
Dependencies go only in one direction
Repositories return Aggregates through their root
More smells …
Transaction Script
Anemic Domain Model
Fighting the Anemic Domain Model
• Do not expose setters
• Do expose only the Aggregate Root
• Do enforce invariants (guard clauses)
• Do mutations only through methods
• Use intent-revealing names (no Update(…) methods)
Make invalid states
impossible to represent
Transaction Script -> Application Service
1. Load
aggregate root
from repository
2. Mutate by
invoking methods
3. Save to DB
Methods on Domain Entities
Intent-revealing
name
Make forbidden
state impossible
Avoid primitive
types
Status
Even better
• Decoupled
• Testable
• Easy to know where
functionality should live
• Explicit models and methods
• Clean encapsulation
• Meaningful names
PRESENTATION
DATA
Application Services
Repositories
Aggregates
What about views ?
We defined
• Small aggregates
• Repositories targeting only
Aggregate Roots
• Transactional consistency
• Repositories hiding data-access
For views / reports we need
• JOINs across many tables
• Small ad-hoc queries on some
tables
• No transactions
• Access to raw data / perf
Different needs require different tools
Separating Reads and Writes
• Commands vs Queries
• Write Model vs Read Model
CQS (Command Query Separation)
CQRS (Command Query Responsibility Segregation)
Aggregates View-specific projections
As big or small as needed
WRITE
READ
Commands
Application Service
Repository
Commands
Commands
1. Load aggregate
from repository
2. Validate / mutate
3. Save changes
Direct
access to
the data
Queries
QueriesQueries
Query Handler
*
* Maybe same as primary, maybe totally
different
Expose only
Aggregates
Write Model Read Model
Allow edits
Read-only
Expose
projections, DTOs
tailored for the
view
Status
Good enough for now ☺
• Decoupled
• Testable
• Easy to know where functionality
should live
• Explicit models and methods
• Clean encapsulation
• Meaningful names
• Correct writes
• Fast Reads
Take aways
• Smoothly introduce DDD
concepts
• Failing is learning
• Watch out for smells
• Continuously improve
• The right tool for the right job
• Context is king
Going further
Some important concepts I left out :
• Value Objects
• Bounded Contexts
• Ubiquitous Language
• Domain Events
• Context Mapping
• …
Thanks for listening !
Questions ? Thibaud Desodt - @tsimbalar

Más contenido relacionado

La actualidad más candente

Work hardening and Baushinger effect
Work hardening and Baushinger effectWork hardening and Baushinger effect
Work hardening and Baushinger effect
Jitender Madhesiya
 

La actualidad más candente (20)

Work hardening and Baushinger effect
Work hardening and Baushinger effectWork hardening and Baushinger effect
Work hardening and Baushinger effect
 
UNDER GROUND COAL GASSIFICATION
UNDER GROUND COAL GASSIFICATION UNDER GROUND COAL GASSIFICATION
UNDER GROUND COAL GASSIFICATION
 
casting defects
casting defectscasting defects
casting defects
 
Investment casting
Investment castingInvestment casting
Investment casting
 
Stainless steel
Stainless steelStainless steel
Stainless steel
 
2 ME casting & solidification
2 ME  casting & solidification 2 ME  casting & solidification
2 ME casting & solidification
 
gypsum
gypsumgypsum
gypsum
 
Investment materials and procedures
Investment materials and proceduresInvestment materials and procedures
Investment materials and procedures
 
Strain Hardening
Strain Hardening Strain Hardening
Strain Hardening
 
Casting procedure & casting defects
Casting procedure & casting defectsCasting procedure & casting defects
Casting procedure & casting defects
 
Casting procedures & defects
Casting procedures & defectsCasting procedures & defects
Casting procedures & defects
 
Custom made post & Core in endodontics
Custom made post & Core in endodonticsCustom made post & Core in endodontics
Custom made post & Core in endodontics
 
Base Metal Casting Alloys in Dentistry by Dr Rashid Hassan
Base Metal Casting Alloys in Dentistry by Dr Rashid HassanBase Metal Casting Alloys in Dentistry by Dr Rashid Hassan
Base Metal Casting Alloys in Dentistry by Dr Rashid Hassan
 
Die casting and types
Die casting and typesDie casting and types
Die casting and types
 
Biomechanical problems associated with free end saddle dentures
Biomechanical problems associated with free end saddle denturesBiomechanical problems associated with free end saddle dentures
Biomechanical problems associated with free end saddle dentures
 
SOLIDIFICATION OF CASTING
SOLIDIFICATION OF CASTINGSOLIDIFICATION OF CASTING
SOLIDIFICATION OF CASTING
 
Alloys in fpd /dental education courses
Alloys in fpd /dental education coursesAlloys in fpd /dental education courses
Alloys in fpd /dental education courses
 
Casting defects
Casting defectsCasting defects
Casting defects
 
Dental ceramics/prosthodontic courses
Dental ceramics/prosthodontic coursesDental ceramics/prosthodontic courses
Dental ceramics/prosthodontic courses
 
3d printing in prosthodontics K V G
3d printing in prosthodontics  K V G3d printing in prosthodontics  K V G
3d printing in prosthodontics K V G
 

Similar a From ddd to DDD : My journey from data-driven development to Domain-Driven Design

CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011
Dennis Traub
 
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk ChoStateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Redis Labs
 

Similar a From ddd to DDD : My journey from data-driven development to Domain-Driven Design (20)

Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
Introducing NoSQL and MongoDB to complement Relational Databases (AMIS SIG 14...
 
Einführung in RavenDB
Einführung in RavenDBEinführung in RavenDB
Einführung in RavenDB
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
Webinar: Migrating from RDBMS to MongoDB
Webinar: Migrating from RDBMS to MongoDBWebinar: Migrating from RDBMS to MongoDB
Webinar: Migrating from RDBMS to MongoDB
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
A Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQLA Journey from Oracle to PostgreSQL
A Journey from Oracle to PostgreSQL
 
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
ГАННА КАПЛУН «noSQL vs SQL: порівняння використання реляційних та нереляційни...
 
CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011CQRS - Eine Einführung - NOUG 2011
CQRS - Eine Einführung - NOUG 2011
 
Transform your DBMS to drive engagement innovation with Big Data
Transform your DBMS to drive engagement innovation with Big DataTransform your DBMS to drive engagement innovation with Big Data
Transform your DBMS to drive engagement innovation with Big Data
 
Scaling tappsi
Scaling tappsiScaling tappsi
Scaling tappsi
 
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
 
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk ChoStateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
Stateful Interaction In Serverless Architecture With Redis: Pyounguk Cho
 
Dbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo PiairoDbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo Piairo
 
DbOps, DevOps and Ops
DbOps, DevOps and OpsDbOps, DevOps and Ops
DbOps, DevOps and Ops
 
Got documents - The Raven Bouns Edition
Got documents - The Raven Bouns EditionGot documents - The Raven Bouns Edition
Got documents - The Raven Bouns Edition
 
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
TechEvent 2019: Oracle to PostgreSQL - a Travel Guide from Practice; Roland S...
 
From Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, LvivFrom Rails legacy to DDD - Pivorak, Lviv
From Rails legacy to DDD - Pivorak, Lviv
 
Demystifying data engineering
Demystifying data engineeringDemystifying data engineering
Demystifying data engineering
 
Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)
 
Beyond The Rails Way
Beyond The Rails WayBeyond The Rails Way
Beyond The Rails Way
 

Último

Último (20)

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

From ddd to DDD : My journey from data-driven development to Domain-Driven Design

  • 1. From ddd to DDD An ongoing journey Thibaud Desodt - @tsimbalar
  • 2. What this is about • Me, myself and I • Code • Architecture • Learning process
  • 3. Where it all started
  • 4. E-commerce site ASP.NET / C# Back-office site “classic” ASP / VbScript Data Tables Stored Procedures T-SQL PRESENTATION BUSINESS LOGIC DATA
  • 5. And it was … • Not super pleasant • VbScript • T-SQL • Fragile • No automated tests • Tight coupling • Schema -> Stored Procs -> Website / admin site
  • 6. … but it worked “well enough”! • Customer value • Happy customer • Fast delivery of features • Reasonable perf • Easy to work on • 1 feature ≈ 1 stored procedure
  • 7. It worked well ... in that context • Working alone on project • Version 1 of the product • Well-defined requirements • Tight interactions with customer • Simple domain = ideal greenfield project
  • 8. A few years later … Similar approach, different context
  • 9. A different context • 40,000+ employees company • 100s of developers spread across the globe • Many different systems accessing the database(s)
  • 10. This scripts that runs every night That excel sheet nobody understands Admin CRUD app Quotation app Data 800+ Tables 3000+ Stored Procedures T-SQL Customer-facing web appsB2B SOAP services Internal Catalogue app Reporting App Bob running random SQL queries The Enterprise Database ™
  • 11.
  • 12. Many issues • Evolution is hard • Testing is hard • Versioning / collaboration is hard • Performance is not great
  • 13. the “solution” …. • Team of 50 DBAs • The “database” committee • The “database” change process • The “meta-database” • Db replication • Governance Technical solutions … to solve technical issues … introduced because of technical decisions … with no value to the users = Accidental complexity
  • 14.
  • 15. Moving away from database-driven • Persistence is an implementation detail • Focus on customer value Relational DB, Document DB, Key-Value store, file … Who cares ? Business > Tech
  • 17. Bringing the logic back to the code • No more Stored Procedures • ORM (Entity Framework in that case) • Data-access code + Entities* generated from database * Not quite
  • 18.
  • 19.
  • 20. Status That’s better ! • No more business logic in the DB • Quite readable Still a bit messy: • Not testable • Hard coupling DATA BUSINESS LOGIC
  • 22. DATA BUSINESS LOGIC Better layering Services Repositories + Unit of Work Abstract away details of how data is accessed Orchestrate data-flow for a given use-case
  • 25. Status Quite an improvement • Decoupled • Testable • Easy to know where functionality should live • It worked fine initially But … wait a minute …
  • 26. Object graphs When loading an Order from DB …what else should I load ? - All the relationships ? - Some of them, and leave some unpopulated (null) ? - Some of them, and use lazy- loading ? define Aggregates Deliberately delimit clusters of objects that live together and are loaded/stored together. … keep them as small as possible
  • 27. Object graphs identify the Aggregate Root The unique entry point to the graph Dependencies go only in one direction Repositories return Aggregates through their root
  • 28. More smells … Transaction Script Anemic Domain Model
  • 29. Fighting the Anemic Domain Model • Do not expose setters • Do expose only the Aggregate Root • Do enforce invariants (guard clauses) • Do mutations only through methods • Use intent-revealing names (no Update(…) methods) Make invalid states impossible to represent
  • 30. Transaction Script -> Application Service 1. Load aggregate root from repository 2. Mutate by invoking methods 3. Save to DB
  • 31. Methods on Domain Entities Intent-revealing name Make forbidden state impossible Avoid primitive types
  • 32. Status Even better • Decoupled • Testable • Easy to know where functionality should live • Explicit models and methods • Clean encapsulation • Meaningful names PRESENTATION DATA Application Services Repositories Aggregates
  • 33. What about views ? We defined • Small aggregates • Repositories targeting only Aggregate Roots • Transactional consistency • Repositories hiding data-access For views / reports we need • JOINs across many tables • Small ad-hoc queries on some tables • No transactions • Access to raw data / perf Different needs require different tools
  • 34. Separating Reads and Writes • Commands vs Queries • Write Model vs Read Model CQS (Command Query Separation) CQRS (Command Query Responsibility Segregation) Aggregates View-specific projections As big or small as needed
  • 35. WRITE READ Commands Application Service Repository Commands Commands 1. Load aggregate from repository 2. Validate / mutate 3. Save changes Direct access to the data Queries QueriesQueries Query Handler * * Maybe same as primary, maybe totally different
  • 36. Expose only Aggregates Write Model Read Model Allow edits Read-only Expose projections, DTOs tailored for the view
  • 37. Status Good enough for now ☺ • Decoupled • Testable • Easy to know where functionality should live • Explicit models and methods • Clean encapsulation • Meaningful names • Correct writes • Fast Reads
  • 38. Take aways • Smoothly introduce DDD concepts • Failing is learning • Watch out for smells • Continuously improve • The right tool for the right job • Context is king
  • 39. Going further Some important concepts I left out : • Value Objects • Bounded Contexts • Ubiquitous Language • Domain Events • Context Mapping • …
  • 40. Thanks for listening ! Questions ? Thibaud Desodt - @tsimbalar