24
Event Sourcing : The Best Ubiquitous Pattern You've Never Heard Of Joe Drumgoole Director of Developer Advocacy, EMEA @jdrumgoole V1.1

Event sourcing the best ubiquitous pattern you have never heard off

Embed Size (px)

Citation preview

Page 1: Event sourcing   the best ubiquitous pattern you have never heard off

Event Sourcing :The Best Ubiquitous Pattern You've Never Heard Of

Joe Drumgoole

Director of Developer Advocacy, EMEA@jdrumgoole

V1.1

Page 2: Event sourcing   the best ubiquitous pattern you have never heard off

2

Event Sourcing – not a new idea

Page 3: Event sourcing   the best ubiquitous pattern you have never heard off

3

Our Relational Friends Love It

Page 4: Event sourcing   the best ubiquitous pattern you have never heard off

4

We do It Ourselves

Page 5: Event sourcing   the best ubiquitous pattern you have never heard off

5

Think of a File backup system

Source Disk

Backup Disk

Page 6: Event sourcing   the best ubiquitous pattern you have never heard off

6

Trivial Backup

Source Disk

Backup DiskMyFile.jpg

Page 7: Event sourcing   the best ubiquitous pattern you have never heard off

7

But…

Source Disk

Backup DiskMyFile.jpg

MyFile.jpg

Page 8: Event sourcing   the best ubiquitous pattern you have never heard off

8

Lets Use a Backup Tool

Source Disk

Backup DiskMyFile.jpg

MyFile.jpg

Admin

Page 9: Event sourcing   the best ubiquitous pattern you have never heard off

9

What if We are a SaaS Backup Company?

MyFile.jpg MyFile.jpg

MyFile.jpg

MyFile.jpg

MyFile.jpg

AuditMyFile.jpg

MyFile.jpgMyFile.jpg

MyFile.jpgMyFile.jpg

MyFile.jpg

MyFile.jpg

MyFile.jpgMyFile.jpg

MyFile.jpgMyFile.jpg

MyFile.jpgMyFile.jpg

MyFile.jpg

Audit

Page 10: Event sourcing   the best ubiquitous pattern you have never heard off

10

What real SaaS Backup Companies do

Event 1MyFile.jpg

Event 2

Event 3

Event 4

Event 5

Event N

MyFile.jpg Start

MyFile.jpg End

Page 11: Event sourcing   the best ubiquitous pattern you have never heard off

11

Where else is this Useful?

Page 12: Event sourcing   the best ubiquitous pattern you have never heard off

How Did I Get Here?

Page 13: Event sourcing   the best ubiquitous pattern you have never heard off

What's in the Box?

Page 14: Event sourcing   the best ubiquitous pattern you have never heard off

An Immutable Append Only Log

Page 15: Event sourcing   the best ubiquitous pattern you have never heard off

Snapshots for point in time state

Page 16: Event sourcing   the best ubiquitous pattern you have never heard off

16

Where Do Events Come From?

Commands

Root Aggregate

Business Events

Aggregate Value

AggregateValue

Event 1

Event 2

Event 3

Event 4

Event 5

Event 6

Event 7

Event 8

Event 9

Event N

Event N + 1

Page 17: Event sourcing   the best ubiquitous pattern you have never heard off

Snapshots for point in time state

Page 18: Event sourcing   the best ubiquitous pattern you have never heard off

18

Some Example Snapshot Queries

• What POs failed to get approved in Q2?• Which cabs billed more than $50 a journey?• Which cabs get the biggest tips?• How many baskets have had $200 for two weeks or more?• Which sensor events exceeded the safety threshold on 21-July-

2016?

Page 19: Event sourcing   the best ubiquitous pattern you have never heard off

CQS

CQRS

Command Query Segregation

Command Query Responsibility Segregation

Begat

Page 20: Event sourcing   the best ubiquitous pattern you have never heard off

20

Split the ResponsibilitiesCommands

CommandsCommands

CommandsCommands

Commands

Domain Objects

EventsEvents

EventsEvents

EventsEvents

EventsEvents

Domain Objects

CommandsCommands

CommandsCommands

CommandsQueries

Query ObjectsQuery Objects

Domain Data

Snapshot

Snapshot

Snapshot

Page 21: Event sourcing   the best ubiquitous pattern you have never heard off

21

In MongoDB SpeakDomain Objects Query Objects

Query Objects

P

S S

Domain Objects

Replica Set/Sharded Cluster Query Cluster

P

S S

Page 22: Event sourcing   the best ubiquitous pattern you have never heard off

22

Domain Object - Eventpurchase_order = { "ID" : "1222-344-27", "timestamp" : "Wed Oct 19 2016 16:50:27 GMT" "dept" : "Manufacturing", "Purchase From" : { "company" : "ABC Ltd", "company number" : 12345678, "VAT ID" : "773456K", "Address" : { ... } } "line items" : [ { ... }, { ... } ], "VAT" : 540.0 "total price" : 2567.54 "currency" : "Euro", "Supplier Ref" : "YF-27-567", "delivery address" : { ...} }

Page 23: Event sourcing   the best ubiquitous pattern you have never heard off

23

Summary

• Event Sourcing : Capture the state as first class objects• CQRS : Optimise differently for commands and queries• MongoDB ideally suited to build both event store and query store• Use different storage engines depending on use case• The aggregation framework generates summary data

Page 24: Event sourcing   the best ubiquitous pattern you have never heard off