CQRS-Einführung - Teil 2

710 views

Published on

Published in: Education, Business, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
710
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • Refactor Application Service Call to Object => CommandCommands can
  • CQRS-Einführung - Teil 2

    1. 1. CQRS – Eine EinführungPt. 2 – Event-Centric Architecture .Net Online Usergroup – 20.02.2011 Presenter: Dennis Traub Speaker, Trainer, Author, Software Developer since 1991 Twitter: @DTraub
    2. 2. CQRS RevisitedDomain EventsAn Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    3. 3. CQRS revisited Data Storage ORM Thin Read Layer Domain Model Command Handlers Commands Queries Client
    4. 4. CQRS RevisitedDomain EventsAn Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    5. 5. Definition: Domain Event• Martin Fowler: (PEAA, 2002) ▫ Captures the memory of something interesting which affects the domain ▫ The essence […] is to capture things that can trigger a change to the state ▫ These event objects are then processed to cause changes to the system, and stored to provide an audit log
    6. 6. State Shopping Cart
    7. 7. What we dont know:What led to this state?
    8. 8. Added to Cart
    9. 9. Added Added to to Cart Cart
    10. 10. Added Added Added to to to Cart Cart Cart
    11. 11. Added Added Added Removed to to to from Cart Cart Cart Cart
    12. 12. Which model contains more Information?
    13. 13. This one? Shopping Cart
    14. 14. Or this one? Added Added Added Removed to to to from Cart Cart Cart Cart
    15. 15. What if we capture every single event?
    16. 16. And reproduce state from this stream of events?
    17. 17. An Event Stream …Added Added Added Removed to to to from Cart Cart Cart Cart
    18. 18. An Event Stream …Added Added Added Removed to to to from Cart Cart Cart Cart Shopping Cart Can be projected into:
    19. 19. An Event Stream …Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Shopping Cart … or into this:
    20. 20. An Event Stream …Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Audit Trail Shopping Cart … or into this:
    21. 21. An Event Stream …Added Added Added Removed to to to from Cart Cart Cart Cart Sales History Campaign Effectiveness Shopping Campaign Effectiveness Cart … or into this:
    22. 22. CQRS RevisitedDomain EventsTowards an Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    23. 23. Simple CQRS Relational Data SQL Storage Views ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    24. 24. Optimized Write / Complex to Read INNER JOIN … LEFT OUTER JOIN … Relational Data UNION … SQL Storage GROUP BY … Views ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    25. 25. Optimized Write / Complex to Read INNER JOIN … LEFT OUTER JOIN … Relational Data UNION … SQL Storage GROUP BY … Views ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    26. 26. Replace Views with Table per Query SELECT * FROM … Table Relational Data per Storage Query ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    27. 27. Emit Events when they occur Table Relational Data per Storage View ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    28. 28. Denormalize Events into Read Model Denormalizer Table Relational Data per Storage View ORM Thin Read Layer Domain Model Command HandlersCommands Queries Client
    29. 29. Add an Event Log for future retrieval Denormalizer Table Relational Data per Storage View ORM Thin Read Layer Domain Model Command HandlersCommands Event Log Queries Client
    30. 30. Simplified: Events Domain Read Model Commands DTOs Client
    31. 31. CQRS RevisitedDomain EventsTowards an Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    32. 32. Denormalized Store:If ISBN exists in ShoppingCartDetails Increase AmountElse Add New Row
    33. 33. Denormalized Store:If Shopping Cart ID exists in ShoppingCartSummary Increase Number of Items Add Offered Price to Total AmountElse Add New Row
    34. 34. Denormalized Store:If Amount > 1 in ShoppingCartDetails Decrease AmountElse Delete Row
    35. 35. Denormalized Store:Subtract Offered Price from Total AmountDecrease Number of Items
    36. 36. CQRS RevisitedDomain EventsTowards an Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    37. 37. Testing the Read Model Denormalizer Table per View Thin Read Layer
    38. 38. Testing the Read ModelGiven that certain Events have occurred Denormalizer Table per View Thin Read Layer
    39. 39. Testing the Read ModelGiven that certain Events have occurred Denormalizer Table perWhen a specific Event has occurred View Thin Read Layer
    40. 40. Testing the Read ModelGiven that certain Events have occurred Denormalizer Table perWhen a specific Event has occurred View Thin Read LayerThen each query should produce the expected results
    41. 41. Testing the Read ModelGiven that a book with an ISBN of xxx and a price of USD 24.00 was added to a new shopping cartWhen a book with an ISBN of yyy and a price of USD 19.00 was added to that same shopping cartThen the Shopping Cart Summary should contain 2 books and have a total amount of USD 43.00And the Shopping Cart Details should contain book xxxAnd the Shopping Cart Details should contain book yyy
    42. 42. Testing the Write Model Domain Model Command Handlers
    43. 43. Testing the Write Model Given that certain Events have occurred Domain Model Command Handlers
    44. 44. Testing the Write Model Given that certain Events have occurred Domain Model Command Handlers When a specific Commands is sentCommands
    45. 45. Testing the Write Model Then the expected Events (and only those) should be emitted Given that certain Events have occurred Domain Model Command Handlers When a specific Commands is sentCommands
    46. 46. Testing the Write ModelGiven that an Add Book To Shopping Cart event with an ISBN of xxx had been sentWhen a Remove Book From Shopping Cart command is sent with an ISBN of zzzThen a Book Removal Failed event should be emittedAnd NO Book Was Removed From Shopping Cart event should be emitted
    47. 47. CQRS RevisitedDomain EventsTowards an Event-Centric ArchitectureSome CodeWhat about Testing?Summary
    48. 48. Main Value:• Additive only, i.e. we don‘t lose information• Linearly scalable and distributable Read Model• Every new view can be created from the beginning of time• We can come up with new questions at any time• Built-In Integration Model
    49. 49. Proven Technology:Mature business models move away fromUpdate/Delete and become purely transactional: ▫ Human Resources ▫ Banking ▫ Medicine ▫ Financial Trading ▫ Bookkeeping ▫ Government ▫ …
    50. 50. What we haven‘t touched yet: ▫ Messaging ▫ Eventual Consistency ▫ Event Sourcing ▫ Integration Scenarios ▫ Sagas ▫…
    51. 51. Resources• http:// cqrs.wordpress.com• http:// groups.google.com/group/dddcqrs• http:// distributedpodcast.com• http:// abdullin.com/cqrs• http://cqrs.wikidot.com
    52. 52. Vielen Dank! Dennis Traub @Dtraub Please rate this talk at: bit.ly/xyb4tx

    ×