Slide 1

Slide 1 text

Buildıng a tıme machine with event sourcıng Alper Hankendi @alper_hankendi github.com/alperhankendi

Slide 2

Slide 2 text

Agenda ➔ Getting Started Event Sourcing ➔ History of Event Sourcing ➔ Building Aggregates ➔ Projections ➔ Rolling Snapshot ➔ Related Concepts ➔ Evolution of Event Sourcing

Slide 3

Slide 3 text

Once upon a time...

Slide 4

Slide 4 text

Scalıng up...

Slide 5

Slide 5 text

Let’s go asynchronous

Slide 6

Slide 6 text

COMMAND SOURCING

Slide 7

Slide 7 text

COMMANDs >>> Event sourcing

Slide 8

Slide 8 text

COMMANDS vs events Command “Create Account” —> A request (imperative sentence) —> May fail —> May affect multiple Aggregates Rebuild Aggregate State From Commands

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

What about reads?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

CQRS and Event sourcıng

Slide 14

Slide 14 text

Projections

Slide 15

Slide 15 text

What about event storage?

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Event sourcing “Capture all changes to an application state as a sequence of events. “ M.Fowler

Slide 19

Slide 19 text

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!

Slide 20

Slide 20 text

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”

Slide 21

Slide 21 text

More concepts...

Slide 22

Slide 22 text

A couple of concepts from ddd

Slide 23

Slide 23 text

Interactıon wıth aggregates

Slide 24

Slide 24 text

Commands Events Projections

Slide 25

Slide 25 text

EVENT STORE Bank Account Created Deposited Withdrawn Change Owner Deposited

Slide 26

Slide 26 text

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...

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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.

Slide 29

Slide 29 text

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.

Slide 30

Slide 30 text

Gettıng and Savıng aggregates

Slide 31

Slide 31 text

Evolutıon of ddd -- cqrs & event sourcıng -- event storming

Slide 32

Slide 32 text

A couple of concepts from event stormıng

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

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!