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

DDDVienna - Applying event sourcing and CQRS in...

DDDVienna - Applying event sourcing and CQRS in a large ERP system

In the last 7 years we have applied event sourcing and CQRS in the development of our new ERP system. During this process we have run into some interesting challenges and we have come up with solutions. In this session I would like to present these patterns and get your feedback on them.

Michiel Overeem

October 04, 2019
Tweet

More Decks by Michiel Overeem

Other Decks in Technology

Transcript

  1. 1996 – AFAS starts 2011 (jan) – First steps in

    CQRS and event sourcing 2011 (dec) – Started at AFAS 2020 – Live Via JTeam/Trifork/Axon. 2016 – Started on evolution
  2. 20 years of ERP 10.000 customers 90% cloud Person Entity

    Customer Role Order Agreement party Spending limit Address Organisation Entity Delivery BusinessAc tivity party Invoice BusinessAc tivity party Address Address Spending limit Spending limit Own Organisation Workarea workarea Spending limit Put all our knowledge and experience in a model
  3. Customized Web Scalable CQRS Event sourcing Person Entity Customer Role

    Order Agreement party Spending limit Address Organisation Entity Delivery BusinessAc tivity party Invoice BusinessAc tivity party Address Address Spending limit Spending limit Own Organisation Workarea workarea Spending limit
  4. Event store Aggregate root Command Event store Event Projector Query

    store Event Queue Query request Query handler Aggregate root Command Projector Event Queue Query store
  5. Event store Aggregate root Command Event store Event Projector Query

    store Event Queue Query request Query handler Aggregate root Command Projector Event Queue Query store Data of different projectors can not be joined. Tables are fully inlined, no joins.
  6. Aggregate root Command Event store Event Projector Query store Event

    Queue Query request Query handler • Aimed at CRUD • MongoDB, *SQL, DocumentDB • MS Orleans, MS Service Fabric • SPA-frontend
  7. Evolution as a feature of the model? Person Entity Customer

    Role Order Agreement party Spending limit Address Organisation Entity Delivery BusinessAc tivity party Invoice BusinessAc tivity party Address Address Spending limit Spending limit Own Organisation Workarea workarea Spending limit
  8. Data upgrade Deployed with Executed by Executed by Data upgrade

    Application upgrade Lazy transformation Upcasting In place transfor- mation Multiple versions Copy and transfor- mation Basic & Complex Event Basic & Complex Stream Basic Store Complex Store Big Flip Rolling Upgrade Blue-Green Expand- Contract Blue- Green Deployed with Combined with Weak schema Expensive!
  9. Aggregate root Command Event store Event Projector Query store Event

    Queue Query request Query handler Can give error (needs retry). Command-side in control over publishing.
  10. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Projector in control. More load on the event store.
  11. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager But what if these commands fail?
  12. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store
  13. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Commands that cannot fail become events. We still have some internal commands.
  14. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Different instances to scale the work. Event sourced for state.
  15. Aggregate root / Process manager Command Event store Event Projector

    Query store Query request Query handler Is this what we want?
  16. Aggregate root / Process manager Command Event store Event Projector

    Query store Query request Query handler Is this what we want? Technically there is no difference between aggregates and processmanagers
  17. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store
  18. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Process manager Process manager Process manager Aggregate root Aggregate root Aggregate root Aggregate root
  19. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Process manager Process manager Process manager Aggregate root Aggregate root Aggregate root Aggregate root These ProcessManager all need the same data (lots of data)
  20. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Stream Projector Query store Event store
  21. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Process manager Event store Stream Projector Query store Event store StreamProjectors are single-instanced, non- event-sourced processmanagers
  22. Counter Process Manager Count Command Counted Event Event store Counter

    Projector Query store Get Counter Count Query handler Getting the next consecutive number in a series.
  23. Counter Process Manager Count Command Counted Event Event store Counter

    Projector Query store Get Counter Count Query handler When is the value ready? Correlationid?
  24. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Client Using websockets to notify the Client
  25. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Client Returning values from the produced event directly
  26. Counter Process Manager Count Command Counted Event Event store Counter

    Projector Query store Get Counter Count Query handler
  27. Aggregate root Command Event store Event Projector Query store Query

    request Query handler Stream Projector Query store Event store 557 464 1927 4849 1075 2718 801 1479
  28. Aggregate root Command Event store Event Aggregate root Event store

    Event These events now serve multiple goals. Team B Team A
  29. Aggregate root Command Event store Event Aggregate root Event store

    Event Team B Team A Sync Event store Event
  30. Aggregate root Command Event store Event Aggregate root Event store

    Event Team B Team A Sync Event store Event Introduce synchronization events.
  31. Copyright Nasa Goddard Michiel Overeem @michielovereem • No event bus

    • Commands do have results • Projectors can publish events • Aggregates can listen to events • You can do what you want ☺ i.e. you do not have to listen to a consultant that does not know your context.