$30 off During Our Annual Pro Sale. View Details »

7 Years of DDD: Tackling Complexity in Marketing Systems

7 Years of DDD: Tackling Complexity in Marketing Systems

Turns out Domain-Driven Design works not only for cargo shipping, but for marketing systems as well. In this session I’d like to share the story of Plexop - a large-scale marketing system that spans over a dozen of different business domains: from optimizing advertising spaces, to managing sales agents’ commissions. Plexop had to be implemented with tight resources, and even tighter time to market. That’s why we embraced Domain-Driven Design from day one, and boy did it pay out. I’ll show how DDD allowed us deliver Plexop on time and on budget: what worked, what didn’t, what we had to learn ourselves, and the prices we paid when tried to cut corners.

Vladik Khononov

February 01, 2018
Tweet

More Decks by Vladik Khononov

Other Decks in Programming

Transcript

  1. 7 YEARS OF DDD:
    TACKLING
    COMPLEXITY

    IN LARGE SCALE
    MARKETING SYSTEMS

    View Slide

  2. Vladik Khononov
    IAF Malam Team MSN-IL Cellcom Internovus
    Twitter: @vladikk


    Blog: vladikk.com

    View Slide

  3. Vladik Khononov
    IAF Malam Team MSN-IL Cellcom Internovus
    Twitter: @vladikk


    Blog: vladikk.com

    View Slide

  4. AGENDA

    View Slide

  5. PART 1

    5 BOUNDED
    CONTEXTS
    PART 2
    PRACTICAL
    ADVICE

    View Slide

  6. View Slide

  7. YAY!!!

    View Slide

  8. Your Product Marketing

    Strategy
    Creatives Campaigns Sales

    Agents
    Optimization
    Profits

    View Slide

  9. THE FIRST
    BOUNDED CONTEXT
    01

    View Slide

  10. VER 1.0
    Media Buying
    Creatives Catalog
    Campaign Management

    View Slide

  11. View Slide

  12. View Slide

  13. Very nice!

    View Slide

  14. Aggregates everywhere!!!

    View Slide

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

    View Slide

  16. 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

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

    View Slide

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

    View Slide

  19. UBIQUITOUS LANGUAGE

    View Slide

  20. Domain Expert
    Software Developer
    Has no experience in online marketing
    Nice people!

    View Slide

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

    View Slide

  22. Ubiquitous Language
    Anemic Domain Model

    View Slide

  23. Leads Sales Agents
    Ads

    View Slide

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

    View Slide

  25. View Slide

  26. Lead qualification
    Agent qualification
    Agents’ commissions

    View Slide

  27. THE CRM
    BOUNDED CONTEXT
    02

    View Slide

  28. Ubiquitous Language
    Anemic Domain Model

    View Slide

  29. 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

  30. Domain Expert
    Software Developer
    …. Lead ….
    …. Campaign…

    View Slide

  31. View Slide

  32. View Slide

  33. BOUNDED CONTEXTS
    PROTECT THE LANGUAGE
    AGGREGATES PROTECT
    CONSISTENCY OF DATA

    View Slide

  34. 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

  35. 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

  36. Aggregates will:

    • Protect transactional boundaries

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

    View Slide

  37. Aggregates will:

    • Protect transactional boundaries

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

    View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. Stored
    procedures???

    View Slide

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

    View Slide

  43. L e a d
    CRM Team DBA Team

    View Slide

  44. View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  48. Ubiquitous Language
    Domain Model
    Bounded Contexts
    Protect w/ Implement as
    …Dude, where are Sub-Domains?

    View Slide

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

    Eric Evans

    View Slide

  50. THE CRUNCHERS
    BOUNDED CONTEXT
    03

    View Slide

  51. Marketing CRM Analysis
    Customer
    Events
    Marketing CRM

    View Slide

  52. Marketing
    CRM
    Analysis
    Customer
    Events
    Event
    Crunchers

    View Slide

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

    View Slide

  54. Layered Architecture
    Transaction Script
    Worked
    …. for a while

    View Slide

  55. Customer
    Events
    Event
    Crunchers
    Marketing
    CRM
    Analysis
    Flag Flag
    Calculated fields

    View Slide

  56. View Slide

  57. Marketing
    CRM
    Analysis
    Customer
    Events
    Event
    Crunchers

    View Slide

  58. Customer
    Events
    Event Crunchers
    (BBOM)
    CRM
    Marketing
    Analysis

    View Slide

  59. Customer
    Events
    Event
    Crunchers
    (Event Sourced)
    CRM
    Marketing
    Analysis

    View Slide

  60. THE BONUSES
    BOUNDED CONTEXT
    04

    View Slide

  61. Sales Commissions Reports

    View Slide

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

    View Slide

  63. Active Record
    Service / Application Layer
    Presentation
    Infrastructure

    View Slide

  64. 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

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

    View Slide

  66. Active Record
    Service / Application Layer
    Presentation
    Infrastructure
    Transaction Script
    Service / Application Layer
    Presentation
    Infrastructure
    Event Crunchers Bonuses

    View Slide

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

    View Slide

  68. Event Sourced Domain Model
    Service / Application Layer
    Presentation
    Infrastructure
    Event Sourced Domain Model
    Service / Application Layer
    Presentation
    Infrastructure
    Event Crunchers Bonuses
    Ubiquitous Language

    View Slide

  69. Ubiquitous Language
    Core
    Bounded Contexts
    Protect by

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

    View Slide

  70. THE MARKETING HUB
    BOUNDED CONTEXT
    05

    View Slide

  71. Leads Marketing Hub
    Client
    Client
    Client

    View Slide

  72. Competitive advantage? - Yes
    => Core Domain

    View Slide

  73. Event Sourced Domain Model
    CQRS
    Microservices

    View Slide

  74. Micro

    Service
    Micro

    Service
    Micro

    Service
    Micro

    Service

    View Slide

  75. Aggregate
    Aggregate
    Aggregate
    Aggregate

    View Slide

  76. Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  77. Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  78. Event Sourced Domain Model
    CQRS
    Microservices

    View Slide

  79. Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  80. TECHNICAL
    COMPLEXITY
    BUSINESS
    COMPLEXITY
    >

    View Slide

  81. Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  82. Marketing
    Bonuses
    U D
    CRM
    U
    D
    Marketing

    Hub
    U U
    D
    D
    Event
    Crunchers
    U
    D
    U D

    View Slide

  83. WHAT

    WE HAVE
    L E A R N E D

    View Slide

  84. UBIQUITOUS
    LANGUAGE
    01

    View Slide

  85. Ubiquitous Language:
    The Core Domain of Domain-Driven Design

    View Slide

  86. UBIQUITOUS
    LANGUAGE
    DOCUMENTS
    TESTS
    JIRA
    >

    View Slide

  87. 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

  88. Invest in the Ubiquitous Language early on.

    View Slide

  89. Cheap!

    View Slide

  90. You don’t need a budget for a Ubiquitous Language

    View Slide

  91. DOMAIN
    TYPES
    02

    View Slide

  92. Core
    Supporting
    Generic

    View Slide

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

    View Slide

  94. COMPANIES CHANGE, EVOLVE, REINVENT THEMSELVES
    DOMAINS' TYPES CAN CHANGE ACCORDINGLY

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  101. IMPLEMENTATION
    STRATEGIES
    03

    View Slide

  102. How to Model the Business Logic?
    Transaction Script
    Active Record
    Domain Model
    Event Sourced Domain Model

    View Slide

  103. 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

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

    View Slide

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

    View Slide

  106. Transaction Script
    Active Record
    Domain Model
    Event Sourced Domain Model

    View Slide

  107. PAIN?
    BUSINESS CHANGED?
    DOMAIN TYPE CHANGED?
    REVISE IMPLEMENTATION STRATEGY?

    View Slide

  108. Transaction Script
    Active Record
    Domain Model
    Event Sourced Domain Model

    View Slide

  109. CQRS
    04

    View Slide

  110. Event Sourcing ➤ CQRS

    View Slide

  111. EVENT SOURCING
    A WAY OF MODELING BUSINESS DOMAINS
    CQRS
    ARCHITECTURAL PATTERN FOR REPRESENTING
    THE SAME DATA IN DIFFERENT MODELS

    View Slide

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

    View Slide

  113. 05
    BOUNDED
    CONTEXTS

    View Slide

  114. 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

  115. Bonuses
    Event
    Crunchers
    DOMAIN-BASED BOUNDARIES

    View Slide

  116. AGGREGATE-BASED BOUNDARIES
    Aggregate
    Aggregate
    Aggregate
    Aggregate

    View Slide

  117. L e a d
    SUICIDAL BOUNDARIES

    View Slide

  118. View Slide

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

    Udi Dahan

    View Slide

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

    View Slide

  121. START WITH BIGGER BOUNDARIES
    DECOMPOSE LATER, AS YOU GAIN KNOWLEDGE

    View Slide

  122. THE LESS YOU KNOW ABOUT THE DOMAIN -
    THE WIDER THE INITIAL BOUNDARIES ARE

    View Slide

  123. Aggregate
    Aggregate
    Aggregate
    Aggregate
    Event
    Sourced

    Aggregate

    View Slide

  124. 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

  125. 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

  126. START WITH BIGGER BOUNDARIES
    DECOMPOSE AS YOU GAIN DOMAIN KNOWLEDGE

    View Slide

  127. 1. Ubiquitous Language is not optional
    2. Domain Types change. Embrace these changes
    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. Start with bigger boundaries, and divide as you gain domain knowledge

    View Slide

  128. 07
    SUMMARY

    View Slide

  129. Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

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

    Business

    View Slide

  130. Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

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

    Business

    View Slide

  131. Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

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

    Business

    View Slide

  132. Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

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

    Business

    View Slide

  133. Ubiquitous Language
    Bounded Contexts
    Protect by

    decomposing to
    Design

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

    Business

    View Slide

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

    View Slide

  135. 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

  136. P.S.

    View Slide

  137. View Slide

  138. QUESTIONS?

    View Slide

  139. THANK YOU!
    @vladikk
    http://vladikk.com

    View Slide