Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DDD, CQRS, ES lessons learned

1,698 views

Published on

DDD, CQRS and ES: lessons learned (and walls bumped into)

Published in: Technology

DDD, CQRS, ES lessons learned

  1. 1. DDD, CQRS & ES: Lessons Learned (and walls bumped into) @GitteTitter proq.blogspot.com
  2. 2. One does not simply Use DDD, CQRS & ES
  3. 3. UI Event Store Repository Events Command Handler Command Command Bus Commands Domain Model Domain Model Domain Model Aggregates Event Bus Event Handler Data Thin Data Layer Query DTO Events
  4. 4. https://github.com/MarkNijhof/Fohjin
  5. 5. Problem 1
  6. 6. “Every ‘dossier’, ‘scan’, ‘decision’, ... Should have a unique incremental number”
  7. 7. UI Event Store Repository Events Command Handler Command Command Bus Commands Domain Model Domain Model Domain Model Aggregates Events Use an Event Bus Event Handler Data Thin Data Layer Query DTO autoincrement column? Use a ‘DossierNumberGenerator’
  8. 8. DossierNumberGenerator _highestNumber = 0 1. GenerateNext 2. DossierNumberGeneratedEvent 3. onDossierNumberGenerated _highestNumber ++;
  9. 9. Repository.GetById<DossierNumberGenerator>(id); DossierNumberGenerator _highestNumber = 0 onDossierNumberGenerated _highestNumber ++; DossierNumberGeneratedEvent DossierNumberGeneratedEvent DossierNumberGeneratedEvent Replay
  10. 10. Problem 2
  11. 11. DomainEvent Id EventProviderId Version Raised repo.GetById<EventProvider>(eventproviderId); Get events based on type, not on eventproviderId?
  12. 12. Migrate those events
  13. 13. Read the entire event stream Save the entire event stream WIP ANewRefactoredAggregate AnotherNewRefactoredAggregate anAggregate SomeEvent SomeOtherEvent AndSomeMoreEvent Migration Process SomeEvent SomeOtherEvent AndSomeMoreEvent AndAFunkyEvent Event Store Event Store https://github.com/NEventStore/NEventStore.Migrations https://github.com/vermegi/Eventstream.Migrator
  14. 14. UI Event Store Repository Events Command Handler Command Command Bus Commands Domain Model Domain Model Domain Model Aggregates Event Bus Event Handler Data Thin Data Layer Query DTO Events Replay needed!
  15. 15. Event Versioning with an EventUpdater
  16. 16. Repository.GetById<AnAggregate>(aggregateId); AnAggregate _somePrivateStuff = 0 onSomeEvent: _somePriveStuff = somevalue; SomeEvent AnotherEvent AndAnotherEvent Replay
  17. 17. Repository.GetById<AnAggregate>(aggregateId); SomeEvent AnotherEvent AndAnotherEvent Update SomeUpdatedEvent AnotherEvent AndAnotherEvent AndAnotherEvent
  18. 18. Problem 3
  19. 19. Repository.GetById<AnAggregate>(aggregateId); AnAggregateSnapshot _version = 666 SomeEvent Version = 667 AnotherEvent Version = 668 AndAnotherEvent Version = 669 AnAggregate _somePrivateStuff = 0 onSomeEvent: _somePriveStuff = somevalue; Replay
  20. 20. Problem 4
  21. 21. Hard to use in debugging Hard to do data updates Hard to query
  22. 22. Problem 5
  23. 23. AnAggregate _somePrivateValue = 0 DoSomething DoSomething SomethingHappenedEvent onSomethingHappened _somePrivateValue = something; WIP https://github.com/vermegi/ReplayDomain
  24. 24. Reuse the same logic UI Event Store Repository Events Command Handler Command Command Bus Commands Domain Model Domain Model Domain Model Aggregates Event Bus Event Handler Data Thin Data Layer Query DTO Events Hard to do data updates Do it functional
  25. 25. Problem 6
  26. 26. And for the good news?
  27. 27. Some final thoughts ...
  28. 28. Thank you!

×