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

Extreme DDD Modelling Patterns

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
Tweet

More Decks by Alberto Brandolini

Other Decks in Programming

Transcript

  1. 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
  2. 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)
  3. 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
  4. Consistent with User’s Expectation Coherent with semantics name currentBalance lastUpdatedOn

    Account registerSnapshot trackOperation name currentBalance lastUpdatedOn AccountTracker registerSnapshot trackOperation 😵 Ubiquitous Language? Account
  5. 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
  6. 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
  7. 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
  8. Labels can make you happy All Inclusive Bundle Catalog Item

    Not cool enough to be mentioned by marketing
  9. Maybe we’re not selling our inventory after all… Maybe we’re

    always selling a bundle, which sometimes is simple 🤔 🤔
  10. A Flat Dictionary can be a force in the wrong

    direction 💡 Make sure your Dictionary reflects your bounded contexts
  11. Bounded Context • Limit of applicability of a model •

    Unit of language consistency • A single model tailored around a specific purpose Bounded Context
  12. 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
  13. 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
  14. 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
  15. 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.
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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”
  29. 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
  30. A single use case might not be enough We are

    in the core: some principles are not dogmas 🤔 🤔
  31. 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
  32. 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.
  33. 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]?
  34. 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
  35. More Options Hybrid Trainings Combo Tickets Composite Events Resellers and

    Partners Conferences and Workshops Books as Courseware
  36. 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
  37. 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
  38. How much of this journey can involve domain experts? I

    suspect “It Depends” is a clear winner here. 🤔 🤔
  39. 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
  40. 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
  41. 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?
  42. 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
  43. I can show you Everything! I just need to see:

    UNCONFIRMED CONFIRMED RUNNING PAST CANCELED
  44. 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! … … … …
  45. Digital Tools are changing your brain priorities I enter a

    session to model, and I find myself aligning rectangles and making arrows clear.
  46. 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
  47. Lightweight Boundaries Postpone physical separation as long as you can.

    Make sure your team has enough discipline to support the logical separation.
  48. 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?
  49. What is visible? Read Models Aggregates UI Not everything needs

    to be discussed in the same way Commands (Labels and Intentions) Commands Events Policies
  50. 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