Share
Embed
Extreme DDD Modelling Patterns
What happens when you are free to implement and decide to embrace Domain-Driven Design and Event Sourcing to the extreme consequences?
Alberto Brandolini
November 03, 2024
Transcript
114 slides
-
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 -
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) -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 Billing Product 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 Billing Product 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 Forecast Global 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 Billing Product 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 Forecast Global 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 Billing Product 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 -
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? Policy Event
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 -
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 -
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 Registrations Registration 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 -
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 -
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? -
Read Model Con fi rm 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 -
I can show you Everything! I just need to see:
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! … … … … -
Digital Tools are changing your brain priorities I enter a
session to model, and I find myself aligning rectangles and making arrows clear. -
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 -
Lightweight Boundaries Postpone physical separation as long as you can.
Make sure your team has enough discipline to support the logical separation. -
I’ll follow you everywhere my beloved domain expert!! Why don’t
we just patch the legacy? -
You Can Start Clean Quick and Dirty is not the
only option -
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 -
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