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

Building_time_machine_with_Event_Sourcing.pdf

 Building_time_machine_with_Event_Sourcing.pdf

Bc7114ad3cf4d2d703dc71782e61ba43?s=128

Alper Hankendi

June 23, 2020
Tweet

Transcript

  1. Buildıng a tıme machine with event sourcıng Alper Hankendi @alper_hankendi

    github.com/alperhankendi
  2. Agenda ➔ Getting Started Event Sourcing ➔ History of Event

    Sourcing ➔ Building Aggregates ➔ Projections ➔ Rolling Snapshot ➔ Related Concepts ➔ Evolution of Event Sourcing
  3. Once upon a time...

  4. Scalıng up...

  5. Let’s go asynchronous

  6. COMMAND SOURCING

  7. COMMANDs >>> Event sourcing

  8. COMMANDS vs events Command “Create Account” —> A request (imperative

    sentence) —> May fail —> May affect multiple Aggregates Rebuild Aggregate State From Commands
  9. COMMANDS vs events Event “Account Created” —> Statement of fact

    (past tense) —> Never fails —> May affect a single Aggregates —> Events are immutable Rebuild Aggregate State From Events
  10. What about reads?

  11. None
  12. None
  13. CQRS and Event sourcıng

  14. Projections

  15. What about event storage?

  16. None
  17. Column Types Partition Keys Clustering Columns Columns Event Table RowId

    text AggregateId text Event Time timespam Event Data blob Event Mapper string RowId AggregateId EventTime EventData EventMapper b7913401-f237-4378-b400-4597d26838fd ABC-001 2019 May 3 00:25:07 { "Owner": "Alper Hankendi", "Name": "TL" } namespace.AccountCreated 220e344d-d16b-4a45-b9c6-71d023320a29 DEF-001 2019 May 5 00:45:15 { "Amount": 233.0, "Description": "" } namespace.Deposited
  18. Event sourcing “Capture all changes to an application state as

    a sequence of events. “ M.Fowler
  19. Advantages of event sourcing —> Split logic from events —>

    Stable record of events, rather than just the final state —> Change logic and re-apply events —> Emit events we don’t need —> Add Logic to them after the fact (events..) —> audit free, yey!
  20. Event Sourcıng..use cases —> When the mode is complex —>

    Going to need additional behavior over time —> Need to re-run according to new rules Payroll , accounting, money/audit, banks and… “any state machine based business login”
  21. More concepts...

  22. A couple of concepts from ddd

  23. Interactıon wıth aggregates

  24. Commands Events Projections

  25. EVENT STORE Bank Account Created Deposited Withdrawn Change Owner Deposited

  26. EVENT STORE UPS! The bank says “Where ıs my commısıon

    ffs”? Bank Account Created Deposited Withdrawn Change Owner Deposited You can’t delete events...
  27. EVENT STORE UPS! The bank says “Where ıs my commısıon

    ffs”? Bank Account Created Deposited Withdrawn Change Owner Deposited you can fıx the past wıth adding a new event WithdrewFix
  28. How do I replay tons of events ? The problem

    is that there may be a large number of events between the beginning of time and the current point. You can imagine that an event stream with a million or many more events would be inefficient to load.
  29. The answer is “rollıng snapshot” Snapshot is a projection of

    the current state of an aggregate at a given point. It presents the desired state when all events to that point have been replayed.
  30. Gettıng and Savıng aggregates

  31. Evolutıon of ddd -- cqrs & event sourcıng -- event

    storming
  32. A couple of concepts from event stormıng

  33. Story Challenges —> Migrating product review data from Legacy system

    —> Big bang is forbidden —> Mobile Application needs backward compatibility —> Scalability (80M visit on product page, 1K command per second) —> Eventual Consistency —> Business Validation on command side
  34. None
  35. FIN @alper_hankendi github.com/alperhankendi source code https://github.com/alperhankendi/event-sourcing-demo ps: code puzzling in

    readme file, fork the code and crack it!