Extreme DDD Modelling Patterns - 2024 Devoxx Poland

ziobrando 220 views 43 slides Jun 24, 2024
Slide 1
Slide 1 of 114
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114

About This Presentation

Updated Devoxx edition of my Extreme DDD Modelling Pattern that I presented at Devoxx Poland in June 2024.

Modelling a complex business domain, without trade offs and being aggressive on the Domain-Driven Design principles. Where can it lead?


Slide Content

Extreme DDD
Modelling
patterns
@ziobrando
2024

Disclaimer
In Domain-Driven Design since the early days
In love with CQRS/ES and EventStorming
Enjoying modelling without trade-offs
Running My own company
Unusual freedom
Eating my own gourmet dogfood

The account that wasn’t
Quick intro

Context
Simple Treasury Module: we need to know the
available liquidity in different accounts
Multiple account types, no integrations via API (we’re
too small/lazy/Poor)

So…
•We need an account.
name
currentBalance
Account
deposit
withdraw

Pick your poison
name
currentBalance
Account
deposit
withdraw
Incoherent
design
Someone
else’s model
bank
Not the
domain name
name
currentBalance
lastUpdatedOn
Account
registerSnapshot
trackOperation
name
currentBalance
lastUpdatedOn
AccountTracker
registerSnapshot
trackOperation

Consistent with
User’s Expectation
Coherent with
semantics
name
currentBalance
lastUpdatedOn
Account
registerSnapshot
trackOperation
name
currentBalance
lastUpdatedOn
AccountTracker
registerSnapshot
trackOperation
! Ubiquitous Language?
Account

Labels can make
you happy
Account

Danger Zone!
•Why did we pick the wrong model first?
•Kahneman’s System one?
•…There’s a little backdoor in our brain
that allows school examples to bypass
validation
•Including examples from speakers on a
stage
name
currentBalance
Account
deposit
withdraw

The Dictionary
Interlude

context
Long Lasting Project (3+ Years) in a large
organisation
Complex domain with a very specific jargon
Legacy core
Glossary built with the best intentions
Still trapped in special cases

The revelation
Photo by Joshua Earle on Unsplash

Every single term from
Marketing was crap!

I’ll follow you
everywhere my
beloved domain
expert!!
I have no clue
where I am going…

Not every information from
the “expert” is suitable to
become part of our model

Room Reservations
Some are assigned at purchase time
Some are assigned at departure time
Rooms can be sold with ancillary services
Upgrades are possible
Money can buy almost everything

Labels can make
you happy
All Inclusive
Bundle
Catalog Item
Not cool enough to
be mentioned by
marketing

Maybe we’re not selling
our inventory after all…
Maybe we’re always selling a bundle, which sometimes is simple
"
"

A Flat Dictionary can be a
force in the wrong
direction
# Make sure your Dictionary reflects your bounded contexts

Experts grown on legacy,
will guide you to rebuild
the legacy

Complex Software in the
small
Or: “how not to grow a Big Ball of Mud”

Bounded Context
•Limit of applicability of a
model
•Unit of language
consistency
•A single model tailored
around a specific purpose
Bounded Context

Good, but not actionable

Proxies to the rescue
•Every proxy has a
variable accuracy
•Unfortunately, most
of these proxies are
only visible in large
organisations
Bounded
Context
Limit of applicability
of a model
Team
Subdomain
Organization
Technology
Legacy

And of course…

In small Organizations…
•People, teams and department stop being relevant
•Everything is pulling towards a monolith
•All we’re left with is Purpose and Business Lines

Is this our Destiny?

In the small scale
•Single database -> Flat Namespace
•Single Project -> IDE doesn’t like Polysemic words
•Small Team -> The Mental Model naturally tends
towards a Flat Namespace

Designing to grow right

Possible Bounded Contexts
Trainings
Consulting
Planning
Marketing
Sales
Billing
Logistics
Webinars
Is Trainings a
Bounded
Context?
Finance

Our idea:
Separate on purpose
Logical separation only (easily reversible mistakes)
See what happens

Mixing is cheaper than
Splitting

Dogfood!

Business Lines first!
Books
Public Trainings
Private Trainings
Consulting
Sponsorships
Public Speaking
Software Delivery
Meetups
Events
Obvious in the large, but our responsibility in the small.

Then “Phases”
Books
Public Trainings
Private Trainings
Consulting
Sponsorships
Public Speaking
Software Delivery
Meetups
Events
Planning Sales Delivery BillingProduct Design Financial
Analysis
Strategy Marketing Inventory

Where are they coming from?
10 years of Orange Stickies on paper rolls?
Independent forces for change?
Some “standard” departments
Gut Feeling?
Perfection is not the goal

Then Purposes -> Models
Something is still missing, but …you got the point
Books
Public Trainings
Private Trainings
Consulting
Sponsorships
Public Speaking
Software Delivery
Meetups
Events
Planning Sales Delivery BillingProduct Design Financial
Analysis
Strategy Marketing Inventory
Date
Picking
Tracking
Value
Tickets and
discounts
Print on
Demand
Personal Availability
Engagement
Strategy
Deals
Pricing
Budget
Contracts &
Engagement
Partnerships
ForecastGlobal
Analysis
Billing
Billing
Scouting
Date
Picking
Content
design
Review
Logistics
Scouting
Courseware and
certificates
Newsletter &
social
Newsletter &
social
Content
Design
Format
Design

Bounded Contexts on a grid
$ Shapes and Distribution
Matters
% Commonalities are visible
% More precise names &
purposes
& Better project structure
in the IDE
We definitely need a map!
Books
Public Trainings
Private Trainings
Consulting
Sponsorships
Public Speaking
Software Delivery
Meetups
Events
Planning Sales Delivery BillingProduct Design Financial
Analysis
Strategy Marketing Inventory
Date
Picking
Tracking
Value
Tickets and
discounts
Print on
Demand
Personal Availability
Engagement
Strategy
Deals
Pricing
Budget
Contracts &
Engagement
Partnerships
ForecastGlobal
Analysis
Billing
Billing
Scouting
Date
Picking
Content
design
Review
Logistics
Scouting
Courseware and
certificates
Newsletter &
social
Newsletter &
social
Content
Design
Format
Design

On a single business line…
It’s a value-creation network!
Looks a lot like EventStorming &
Public Trainings
Planning Sales Delivery BillingProduct Design Financial
Analysis
Strategy Marketing Inventory
Tickets and
discounts
Deals
Pricing
Global
Analysis
Billing
Date
Picking
Logistics
Scouting
Courseware and
certificates
Newsletter &
social
Content
Design
Reservations

Yummy!

Modelling our own flow(s)
And being radical about it

The Draft-Executable-Tracking
Archetype
Draft Model Executable Tracking
Easy to change,
possibly partially
specified
Solid, running on read-
only data
Collecting or
visualizing
Validation
Different Models, very similar languages, different paradigms

Visual Grammar
Aggregate
Read
Model
Command
Value
Object?
PolicyEvent
Person
Unit of
transactional
consistency
Something that
happened: verb in
part tense
Command
Reactive logic:
“Whenever
(event) then
(command)
The information
needed to decide
Read
Model
External
System

A little more complex:
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Open
Event
Printables
Venue
Booking
Ticket
Sale
Purchase
Aggregate
Read
Model

A little more complex
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan
…other possible
Value Objects
Open
Registra
tions
(capacity)
Close
Registrations
Venue
Booking
Purchase

Policies to connect-1
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

Public Training
Event
Coordination
Open
Registra
tions
(capacity)
Close
Registrations
Venue
Booking
Purchase

Policies to connect-2
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Reserve
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

PTE
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Registration
Policy
Ticket
Purchased Attendee
Registered
Courseware
Policy
One more!
Venue
Booking
Purchase
Ticket
Reservation
Policy
Purchase
Started
Purchase
Completed Assign
Ticket

Read Models to summarise
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

PTE
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Ticket
Purchased
Attendee
Registered
Event
Confirmed
Purchase

All good?

Naming pain
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

Public Training
Event
Coordination
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Ticket
Purchased
Attendee
Registered
Event
Confirmed
Horrible names
Venue
Booking
Purchase
Experts will Keep
using the specific
terms like “Meetup”
“Training” or
“Conference”

Redundancy Pain
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

Public Training
Event
Coordination
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Ticket
Purchased
Attendee
Registered
Event
Confirmed
Double Capacity?
Venue
Booking

YaGNI!!!

A single use case might
not be enough
We are in the core: some principles are not dogmas
"
"

Private Trainings
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Deal
Open
Event
Printables
Register
Attendee
Schedule
Confirm
Cancel
Cancel
Attendee
Session
Plan

Private
Training
Coordination
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Attendee
Registered
Event
Confirmed
Private
Training
Coordination
Policy
Deal
signed
Materials
Printed
Very Limited
changes,
without opening
boxes.
Printables

Online Training
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Ticket
Sale
Open
Event
Printables
Register
Attendee
Purchase
Ticket
Open
Sales
Schedule
Confirm
Cancel
Close
Sales
Cancel
Attendee
Session
Plan
Ticket
Plan

Public Online
Training
Policy
Open
Registra
tions
(capacity)
Close
RegistrationsRegistration
Policy
Ticket
Purchased Attendee
Registered
Courseware
Policy
One more!
Delivery
Online
Session
Schedule
Start
Purchase
Very Limited
changes,
without opening
boxes.

Business-Driven Stressors
Can I have [This] without [That]?
Can I have [Reservations] without a [Ticket]?
Is this the Exception or the Rule?
It’s always a [Bundle], sometimes a simple one.
Can I have [This] and [That]?

Online Private
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Deal
Open
Event
Printables
Register
Attendee
Schedule
Confirm
Cancel
Cancel
Attendee
Session
Plan
Ticket
Plan

Private
Online
Training
Policy
Open
Registra
tions
(capacity)
Close
Registrations
Attendee
Registered
Courseware
Policy
One more!
Delivery
Online
Session
Schedule
Start
Deal
signed
Progressively
declining cost
of new options

More Options
Hybrid Trainings
Combo Tickets
Composite Events
Resellers and Partners Conferences and Workshops
Books as Courseware

Top-Down Forces
Interacting with Domain Experts
Detecting Business Lines
Imposing phases and archetypes

Bottom-Up Forces
Detecting Building Blocks - Types
Making Them Safe

Session Layout
•Originally ok with int duration
•Pandemic as a majestic stressor:
•Exact Timing became vital information for online sessions
•Empty spaces become interesting for different activity types
Session
Layout

Parallel Models
Design
Delivery
Session
Plan
Session
Type
Session
Session
Duration
Session
Schedule
Scheduled
Session
On May 17th
On may 17th, 9:30 am
3 Days
Day 1, 9:30 am
Session
Type
Zoom
Google
Calendar

For Reuse!!!

For Business
Composability!!!

How much of this journey
can involve domain
experts?
I suspect “It Depends” is a clear winner here.
"
"

Feeling guilty
Design
Delivery
Session
Plan
Session
Type
Session
Session
Duration
Session
Schedule
Scheduled
Session
Horrible names
On May 17th
On may 17th, 9:30 am
3 Days
Day 1, 9:30 am
Session
Type

Problem with this pattern?
Experts think they’re talking about the same thing:
You know they’re not
Draft Model Executable Tracking
Validation
Propose
Adjust
Annotate
Comment
Finalize
Schedule
Cancel
Session Session Type Session Session Type
Duration
Schedule
Duration
Comment
Measure
Start
Join
Terminate
Session Session Type
Duration

What is visible?
Session
Plan
Ticket
Plan
Training
Summary
Schedule
Public
Event
Ticket
Sale
Open
Event
Session
Type
Session
Session
Duration
Session
Can Domain
Experts help
here?

State as an Illusion
The final trick!

I’ll follow you
everywhere my
beloved domain
expert!!

Read Model
Confirm Retire
Amazing Workshop
With John Doe
June 25 - 2023
90 days till deadline
5 of 16 ticket sold
UNCONFIRMED
Threshold at 8
-John Smith - Early Bird Ticket
-Mario Rossi - Early Bird Ticket
-Francesca Bianchi - Early Bird Ticket
-Sylvie Bouchard - Standard Ticket
-Nick Fury - Special Ticket
The information needed to
make a decision
A few things are
missing, I am lazy

That’s what you want to see!

There’s more than one!
Planning:
Time:
Registration / Sales:

I can show you
Everything!
I just need to see:
UNCONFIRMED
CONFIRMED
RUNNING
PAST
CANCELED

User Perceived State Machine
UNCONFIRMED
CONFIRMED
RUNNING
PAST
CANCELED

User Perceived State Machine
Sales Event Time Read Model
Closed Unconfirmed Future Stealth
Closed Confirmed Future Confirmed
Closed Canceled Future Canceled
Open Unconfirmed Future Unconfirmed
Open Confirmed Future Confirmed
Open Canceled Future Error
Closed Unconfirmed Present Forgot something?
Closed Confirmed Present Running
Closed Canceled Present '''''''
Open … Present Hey Wait a Minute!
… … … …

Surprise states!

But…

I’ll couple
everything to give
you the state
machine you
want!

It’s an illusion!

Spice up your models!
Photo by Tamanna Rumee on Unsplash

Give yourself
more than one
option

Add Layers to your whirlpool!

Low-fi Matters

Digital Tools are changing
your brain priorities
I enter a session to model, and I find myself aligning rectangles and
making arrows clear.

Get Yourself a Green Bar!

Combining Different Styles
Little Cherry on top

A Scatter-Gather Style
Design
Planning
Sales
Inventory
Logistics
Tracking
Training
Summary
Public
Event
Open
Event
Printables
Venue
Booking
Ticket
Sale
Purchase
State-Based
Aggregates (or
nobody cares about
your intermediate
events anyway)

Structural
composition and
possible
collaboration
Specifications as
warnings.
Read Models on
Steroids, focus on
information
readability and
sense-making for
the users.
EventSourcing on
multiple parallel
axes: events are
meaningful for the
listeners
Policies -> Sagas or
Process Managers
to allow business
flexibility
Draft Executable Tracking
Possible upscale to
state-driven style
Title

Pick the right tool for the
job

Maybe we can avoid it!

Lightweight Boundaries
Postpone physical separation as long as you can.
Make sure your team has enough discipline to support the logical
separation.

Wrap up!

Biases and shortcuts are
nudging you to repeat past
errors

I’ll follow you
everywhere my
beloved domain
expert!!
Why don’t we just
patch the legacy?

Sometimes we gotta Pull!
Photo by Ugur Arpaci on Unsplash

Design Integrity is
YOUR BUSINESS

Can’t outsource it to the
Domain Expert

You Can Start Clean
Quick and Dirty is not the only option

Give yourself one more
alternatives
Your 1st choice is probably unsafe

What is visible?
Session
Plan
Ticket
Plan
Training
Summary
Schedule
Public
Event
Ticket
Sale
Open
Event
Session
Type
Session
Session
Duration
Session
Can Domain
Experts help
here?

What is visible?
Read Models
Aggregates
UI
Not everything
needs to be
discussed in the
same way
Commands
(Labels and
Intentions)
Commands
Events
Policies

Business Composability
Is
Business Confidence
But make sure it comes from code, not from PowerPoints

Business Composability
Is
Model Confidence

Thanks!

References
•www.eventstorming.com
•LeanPub books:
•http://leanpub.com/introducing_eventstorming (still growing)
•https://leanpub.com/ddd_first_15_years
•Blog:
•https://medium.com/@ziobrando
•http://ziobrando.blogspot.com
•http://blog.avanscoperta.it
•Twitter: @ziobrando
•Trainings & Workshop facilitation: [email protected]
•http://www.avanscoperta.it