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

Alper Hankendi

June 23, 2020
Tweet

More Decks by Alper Hankendi

Other Decks in Programming

Transcript

  1. Agenda ➔ Getting Started Event Sourcing ➔ History of Event

    Sourcing ➔ Building Aggregates ➔ Projections ➔ Rolling Snapshot ➔ Related Concepts ➔ Evolution of Event Sourcing
  2. COMMANDS vs events Command “Create Account” —> A request (imperative

    sentence) —> May fail —> May affect multiple Aggregates Rebuild Aggregate State From Commands
  3. 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
  4. 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
  5. 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!
  6. 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”
  7. 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...
  8. 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
  9. 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.
  10. 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.
  11. 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