Upload
joe-drumgoole
View
227
Download
1
Embed Size (px)
Citation preview
Event Sourcing :The Best Ubiquitous Pattern You've Never Heard Of
Joe Drumgoole
Director of Developer Advocacy, EMEA@jdrumgoole
V1.1
2
Event Sourcing – not a new idea
3
Our Relational Friends Love It
4
We do It Ourselves
5
Think of a File backup system
Source Disk
Backup Disk
6
Trivial Backup
Source Disk
Backup DiskMyFile.jpg
7
But…
Source Disk
Backup DiskMyFile.jpg
MyFile.jpg
8
Lets Use a Backup Tool
Source Disk
Backup DiskMyFile.jpg
MyFile.jpg
Admin
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
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
11
Where else is this Useful?
How Did I Get Here?
What's in the Box?
An Immutable Append Only Log
Snapshots for point in time state
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
Snapshots for point in time state
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?
CQS
CQRS
Command Query Segregation
Command Query Responsibility Segregation
Begat
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
21
In MongoDB SpeakDomain Objects Query Objects
Query Objects
P
S S
Domain Objects
Replica Set/Sharded Cluster Query Cluster
P
S S
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" : { ...} }
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