Upgrade to Pro — share decks privately, control downloads, hide ads and more …

7 Years of Domain-Driven Design

7 Years of Domain-Driven Design

It turns out that domain-driven design works for more than just cargo shipping. Vladik Khononov shares his experience using the domain-driven design methodology at Plexop, a large-scale marketing system that spans over a dozen of different business domains, from the management of advertising spaces to sales agents’ commissions. Vladik and his team had very limited resources and a very short time to market to implement Plexop. He explains how DDD allowed them to manage complexities, discusses different strategies for defining context boundaries, and of course, details the lessons that they learned the hard way.

Vladik Khononov

October 30, 2018
Tweet

More Decks by Vladik Khononov

Other Decks in Programming

Transcript

  1. vladikk
    7 YEARS OF DDD
    or
    Tackling Complexity in

    Large Scale Marketing Systems

    View Slide

  2. YAY!!!

    View Slide

  3. @vladikk
    vladikk.com
    Internovus

    View Slide

  4. vladikk
    PART 2 

    5 PRACTICAL ADVICES
    PART 1

    5 BOUNDED CONTEXTS

    View Slide

  5. View Slide

  6. vladikk
    Your Product Marketing

    Strategy
    Creatives Campaigns Sales

    Agents
    Optimization
    Profits

    View Slide

  7. vladikk
    THE FIRST
    BOUNDED CONTEXT
    01

    View Slide

  8. vladikk
    Media Buying
    Creatives Catalog
    Campaign Management
    VER 1.0

    View Slide

  9. vladikk

    View Slide

  10. vladikk

    View Slide

  11. Very nice!!!1

    View Slide

  12. vladikk
    Aggregates everywhere!!!

    View Slide

  13. vladikk
    Aggregates everywhere!!!
    Creative
    Agency
    Advertiser
    Publisher
    Website
    Placement
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Campaign

    View Slide

  14. vladikk
    The Bounded Context
    Creative
    Agency
    Advertiser
    Publisher
    Website
    Placement
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience

    View Slide

  15. vladikk
    Domain Model
    Service / Application Layer
    Presentation
    Infrastructure
    Anemic!
    Behaviour

    View Slide

  16. vladikk
    Imperfect architecture
    “QA is for cowards”
    BUT IT WORKED!

    View Slide

  17. vladikk
    UBIQUITOUS LANGUAGE

    View Slide

  18. vladikk
    Domain Experts
    Software Developers
    No experience in online marketing
    Nice people!

    View Slide

  19. vladikk
    Smooth communication
    Strong grasp of the business domain
    Working software
    Aggressive time to market

    View Slide

  20. vladikk
    Ubiquitous Language
    Anemic Domain Model

    View Slide

  21. vladikk
    Leads Sales Agents
    Ads

    View Slide

  22. vladikk
    Leads CRM Categorize Desk
    Desk
    Desk
    Sales Agents
    Sales Agents
    Sales Agents

    View Slide

  23. Leads CRM Categorize Desk
    Desk
    Desk
    Sales Agents
    Sales Agents
    Sales Agents
    Clients’ Systems

    View Slide

  24. vladikk

    View Slide

  25. vladikk
    Lead qualification
    Agent qualification
    Agents’ commissions

    View Slide

  26. vladikk
    THE CRM
    BOUNDED CONTEXT
    02

    View Slide

  27. vladikk
    Ubiquitous Language
    Anemic Domain Model

    View Slide

  28. vladikk
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Placement Visit Brand
    Marketing Lead
    CRM Lead
    Marketing Campaign CRM Campaign

    View Slide

  29. vladikk
    Domain Experts
    Software Developers
    …. Lead ….
    …. Campaign…

    View Slide

  30. vladikk

    View Slide

  31. View Slide

  32. vladikk
    BOUNDED CONTEXTS
    PROTECT THE LANGUAGE
    AGGREGATES PROTECT
    CONSISTENCY OF DATA

    View Slide

  33. vladikk
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Placement Visit Brand
    Marketing Lead
    CRM Lead
    Marketing Campaign CRM Campaign

    View Slide

  34. vladikk
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Placement Visit
    Lead
    Campaign
    Marketing
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Brand
    Lead
    Campaign
    CRM

    View Slide

  35. vladikk
    Aggregates will:

    • Protect transactional boundaries

    • Encompass business logic and invariants
    Domain
    Service / Application Layer
    Presentation
    Infrastructure

    View Slide

  36. vladikk
    Aggregates will:

    • Protect transactional boundaries

    • Encompass business logic and invariants
    Domain
    Service / Application Layer
    Presentation
    Infrastructure
    Domain
    Service / Application Layer

    View Slide

  37. View Slide

  38. vladikk

    View Slide

  39. View Slide

  40. vladikk
    Stored
    procedures???

    View Slide

  41. vladikk
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Brand
    Lead
    Campaign
    Lead

    View Slide

  42. L e a d
    CRM Team DBA Team

    View Slide

  43. View Slide

  44. vladikk
    Inconsistent models
    No shared understanding
    Duplication of knowledge
    Went out of sync quickly
    NIGHTMARE

    View Slide

  45. vladikk
    Wasn’t delivered on time
    Production issues
    Data corruption
    Thrown away and reimplemented

    View Slide

  46. vladikk
    Ubiquitous Language
    Domain Model
    Bounded Contexts
    Protect w/ Implement as

    View Slide

  47. Not all of a large system will be well designed

    Eric Evans

    View Slide

  48. vladikk
    THE CRUNCHERS
    BOUNDED CONTEXT
    03

    View Slide

  49. vladikk
    Marketing CRM Analysis
    Customer
    Events
    Marketing CRM

    View Slide

  50. vladikk
    Marketing
    CRM
    Analysis
    Customer
    Events
    Event
    Crunchers

    View Slide

  51. vladikk
    Competitive advantage? - No
    Off-the-shelve solution? - No
    => Supporting sub-domain

    View Slide

  52. vladikk
    Layered Architecture
    Transaction Script
    Worked
    …. for a while

    View Slide

  53. vladikk
    Customer
    Events
    Event
    Crunchers
    Marketing
    CRM
    Analysis
    Flag Flag
    Calculated fields

    View Slide

  54. vladikk

    View Slide

  55. vladikk
    Marketing
    CRM
    Analysis
    Customer
    Events
    Event
    Crunchers

    View Slide

  56. vladikk
    Customer
    Events
    Event Crunchers
    (BBOM)
    CRM
    Marketing
    Analysis

    View Slide

  57. vladikk
    Customer
    Events
    Event
    Crunchers
    (Event Sourced)
    CRM
    Marketing
    Analysis

    View Slide

  58. vladikk
    THE BONUSES
    BOUNDED CONTEXT
    04

    View Slide

  59. vladikk
    Sales Commissions Reports

    View Slide

  60. vladikk
    Competitive advantage? - No
    Off-the-shelve solution? - No
    => Supporting sub-domain

    View Slide

  61. vladikk
    Active Record
    Service / Application Layer
    Presentation
    Infrastructure

    View Slide

  62. vladikk
    Sales Commissions Reports
    Let’s try different percentages
    What if the percentage could be a function
    of a price?
    No, what if the percentage is a function of
    number of sales?
    No, no, the percentage will be a function
    both of number of sales and sale amount
    And another upgrade if there are more
    than Y sales per week!
    But we will upgrade the percentage if
    there are more than X sales per month!

    View Slide

  63. vladikk
    Active Record
    Service / Application Layer
    Presentation
    Infrastructure
    BIG BALL OF MUD

    View Slide

  64. vladikk
    Event Sourced Domain Model
    Service / Application Layer
    Presentation
    Infrastructure
    BIG BALL OF MUD

    View Slide

  65. vladikk
    Active Record
    Service / Application Layer
    Presentation
    Infrastructure
    Transaction Script
    Service / Application Layer
    Presentation
    Infrastructure
    Event Crunchers Bonuses
    Ubiquitous Language

    View Slide

  66. vladikk
    Ubiquitous Language
    Core
    Bounded Contexts
    Protect by

    decomposing to
    Identify
    Domains
    Domain Model
    Supporting
    Generic
    AR / TS
    Adopt
    Implement as

    View Slide

  67. vladikk
    THE MARKETING HUB
    BOUNDED CONTEXT
    05

    View Slide

  68. vladikk
    Leads Marketing Hub
    Client
    Client
    Client

    View Slide

  69. vladikk
    Competitive advantage? - Yes
    => Core Domain

    View Slide

  70. vladikk
    Event Sourced Domain Model
    CQRS
    Microservices

    View Slide

  71. vladikk
    Micro

    Service
    Micro

    Service
    Micro

    Service
    Micro

    Service

    View Slide

  72. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate

    View Slide

  73. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  74. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  75. vladikk
    Event Sourced Domain Model
    CQRS
    Microservices

    View Slide

  76. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  77. vladikk
    TECHNICAL
    COMPLEXITY
    BUSINESS
    COMPLEXITY
    >

    View Slide

  78. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  79. Marketing
    Bonuses
    U D
    CRM
    U
    D
    Marketing

    Hub
    U U
    D
    D
    Event
    Crunchers
    U
    D
    U D

    View Slide

  80. WHAT

    WE HAVE
    L E A R N E D

    View Slide

  81. vladikk
    UBIQUITOUS
    LANGUAGE
    01

    View Slide

  82. vladikk
    UBIQUITOUS LANGUAGE
    THE CORE DOMAIN OF DOMAIN-DRIVEN DESIGN

    View Slide

  83. vladikk
    Marketing
    Ubiquitous Language
    Business goals achieved
    CRM
    Ubiquitous Language
    Production issues
    Long and painful refactoring
    Event Crunchers
    Ubiquitous Language
    Big ball of mud
    Bonuses
    Ubiquitous Language
    Refactored in time

    View Slide

  84. vladikk
    Invest in the Ubiquitous Language early on

    View Slide

  85. vladikk
    Marketing
    Ubiquitous Language
    Business goals achieved
    CRM
    Ubiquitous Language
    Production issues
    Long and painful refactoring
    Event Crunchers
    Ubiquitous Language
    Big ball of mud
    Bonuses
    Ubiquitous Language
    Refactored in time

    View Slide

  86. vladikk
    Cheap!

    View Slide

  87. vladikk
    DOMAIN
    TYPES
    02

    View Slide

  88. vladikk
    Core
    Supporting
    Generic

    View Slide

  89. vladikk
    Generic Domain Adopt / Buy
    Supporting Domain Active Record / Transaction Script
    Core Domain Domain Model / Event Sourcing

    View Slide

  90. vladikk
    COMPANIES CHANGE, EVOLVE, REINVENT THEMSELVES
    DOMAINS' TYPES CHANGE ACCORDINGLY

    View Slide

  91. vladikk
    SUPPORTING ➤ CORE
    • Event Crunchers
    • Bonuses
    SUPPORTING ➤ GENERIC
    • Creative Catalog
    CORE ➤ GENERIC
    • Lead Evaluation System
    CORE ➤ SUPPORTING
    • Marketing Hub
    GENERIC ➤ CORE
    • AWS

    View Slide

  92. vladikk
    Generic Domain Adopt / Buy
    Supporting Domain Active Record / Transaction Script
    Core Domain Domain Model / Event Sourcing

    View Slide

  93. vladikk
    Generic Domain
    Adopt / Buy
    Supporting Domain
    Active Record / Transaction Script
    Core Domain
    Domain Model / Event Sourcing

    View Slide

  94. vladikk
    Less waste
    Dialog with the business
    IMPLEMENTATION DESIGN ➤ DOMAIN TYPE

    View Slide

  95. vladikk
    • Questionable competitive edge?
    • Accidental “business” complexity?
    • Unexpected competitive edge?
    BUSINESS COMPLEXITY ≠ DOMAIN TYPE?

    View Slide

  96. vladikk
    Generic Domain
    Adopt / Buy
    Supporting Domain
    Active Record / Transaction Script
    Core Domain
    Domain Model / Event Sourcing
    IMPLEMENTATION DESIGN ➤ DOMAIN TYPE

    View Slide

  97. vladikk
    IMPLEMENTATION
    STRATEGIES
    03

    View Slide

  98. vladikk
    How to Model the Business Logic?

    View Slide

  99. vladikk
    How to Model the Business Logic?
    Transaction Script (PoEAA)
    Active Record (PoEAA)
    Domain Model (PoEAA + DDD)
    Event Sourced Domain Model

    View Slide

  100. vladikk
    MONEY? DEEP ANALYTICS? AUDIT LOG?
    Event Sourced Domain Model
    COMPLEX BUSINESS LOGIC?
    Domain Model
    COMPLEX DATA STRUCTURES?
    Active Record
    SIMPLE LOGIC, SIMPLE DATA STRUCTURES?
    Transaction Script

    View Slide

  101. vladikk
    MAPPING ARCHITECTURAL PATTERNS
    Event Sourced Domain Model ➤ CQRS
    Domain Model ➤ Hexagonal Architecture
    Active Record ➤ Layered Architecture
    Transaction Script ➤ “Keep it simple” Architecture

    View Slide

  102. vladikk
    MAPPING ARCHITECTURAL PATTERNS
    Event Sourced Domain Model ➤ CQRS
    Domain Model ➤ Hexagonal Architecture
    Active Record ➤ Layered Architecture
    Transaction Script ➤ “Keep it simple” Architecture

    View Slide

  103. vladikk
    Transaction Script
    Active Record
    Domain Model
    Event Sourced Domain Model

    View Slide

  104. vladikk
    PAIN?
    BUSINESS CHANGED?
    DOMAIN TYPE CHANGED?
    REVISE IMPLEMENTATION STRATEGY?

    View Slide

  105. vladikk
    Transaction Script
    Active Record
    Domain Model
    Event Sourced Domain Model

    View Slide

  106. vladikk
    CQRS
    04

    View Slide

  107. vladikk
    Event Sourcing ➤ CQRS

    View Slide

  108. vladikk
    EVENT SOURCING
    BUSINESS DOMAIN MODELING PATTERN
    CQRS
    ARCHITECTURAL PATTERN FOR REPRESENTING
    DATA IN DIFFERENT PERSISTENT MODELS

    View Slide

  109. vladikk
    Transaction Script
    Active Record
    Domain Model
    } Can benefit from CQRS
    and
    State-Based Projections

    View Slide

  110. vladikk
    RDBMS
    Search
    index
    Files

    storage
    Projection

    Engine
    Projected

    Model
    Projected

    Model
    Changes
    Application
    Query
    Query
    Commit

    View Slide

  111. vladikk
    COMMAND QUERY 

    RESPONSIBILITY SEGREGATION?

    View Slide

  112. vladikk
    Did command succeed or fail?
    If failed - why?
    What are the outcomes?
    } Can be delivered
    asynchronously through
    queries
    … but why?

    View Slide

  113. vladikk
    Write

    Model
    Projection
    Projection
    Projection

    Engine
    Projected

    Model
    Projected

    Model
    Changes
    Application
    Client
    Command

    Execution Result
    Query

    View Slide

  114. vladikk
    05
    BOUNDED
    CONTEXTS

    View Slide

  115. vladikk
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Placement Visit
    Lead
    Campaign
    Marketing
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Brand
    Lead
    Campaign
    CRM
    LINGUISTIC BOUNDARIES

    View Slide

  116. vladikk
    Bonuses
    Event
    Crunchers
    DOMAIN-BASED BOUNDARIES

    View Slide

  117. vladikk
    AGGREGATE-BASED BOUNDARIES
    Aggregate
    Aggregate
    Aggregate
    Aggregate

    View Slide

  118. vladikk
    L e a d
    SUICIDAL BOUNDARIES

    View Slide

  119. vladikk

    View Slide

  120. vladikk
    BOUNDED CONTEXTS ARE NOT MICROSERVICES

    View Slide

  121. vladikk
    BOUNDED CONTEXTS
    PROTECT INTEGRITY OF A UBIQUITOUS LANGUAGE

    View Slide

  122. vladikk
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Group
    Desk
    Qualification
    Assessment
    Organization Unit
    Assignment
    Rank
    Message
    On-site Activity
    Placement Visit Brand
    Marketing Lead
    CRM Lead
    Marketing Campaign CRM Campaign

    View Slide

  123. vladikk
    MICROSERVICES
    DECOMPOSITION OF A SYSTEM INTO LOOSELY
    COUPLED COMPONENTS
    BOUNDED CONTEXTS
    PROTECT INTEGRITY OF A UBIQUITOUS LANGUAGE

    View Slide

  124. vladikk
    Micro

    Service
    Micro

    Service
    Micro

    Service
    Micro

    Service

    View Slide

  125. Finding service boundaries is really damn
    hard… There is no flowchart!

    Udi Dahan

    View Slide

  126. vladikk
    THERE ARE GOING TO BE MISTAKES
    ACCEPT IT AND DON’T MAKE FATAL ONES

    View Slide

  127. vladikk
    THE LESS YOU KNOW ABOUT THE DOMAIN
    THE WIDER THE INITIAL BOUNDARIES
    START WITH BIGGER BOUNDARIES
    DECOMPOSE LATER, AS YOU GAIN KNOWLEDGE

    View Slide

  128. vladikk
    Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  129. vladikk
    Marketing
    Creative
    Agency
    Publisher
    Website
    Advertiser
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Audience
    Placement Visit
    Lead
    Campaign

    View Slide

  130. vladikk
    Campaigns
    Creative
    Ad Type
    Agency
    Publisher
    Website
    Zone Type
    Contract
    Budget Unit
    Impression
    Visit
    Lead
    Advertiser
    Target Market
    Funnel
    Audience
    Placement
    Campaign
    Creative Catalog
    Publishers
    Events

    View Slide

  131. vladikk
    START WITH BIGGER BOUNDARIES
    DECOMPOSE AS YOU GAIN DOMAIN KNOWLEDGE

    View Slide

  132. vladikk
    1. Ubiquitous Language is not optional
    2. Domain Types change. Embrace these changes to achieve resilient design
    3. Learn the ins and outs of the four patterns of modeling business logic
    4. Use CQRS to represent the same data in multiple models
    5. Bounded Contexts are not Microservices. Always start with bigger
    boundaries, but decompose further as you gain domain knowledge

    View Slide

  133. vladikk
    SUMMARY

    View Slide

  134. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business

    View Slide

  135. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business

    View Slide

  136. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business

    View Slide

  137. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business

    View Slide

  138. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business

    View Slide

  139. vladikk
    Creative
    Agency
    Advertiser
    Publisher
    Website
    Placement
    Ad Zone
    Ad Type
    Target Market
    Group
    Zone Type
    Funnel
    Contract
    Budget Unit
    Campaign
    Aggregates everywhere!!!

    View Slide

  140. vladikk
    Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

    Implementation
    Core
    Supporting
    Generic
    Domain Model
    AR / TS
    Adopt
    Confirm w/

    Business
    Ubiquitous Language Everywhere!!!

    View Slide

  141. vladikk
    P.S.

    View Slide

  142. vladikk

    View Slide

  143. THANK YOU!
    @vladikk
    vladikk.com

    View Slide