Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
1
Hi.
First, A Quick Scenario
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
5
Balance: $100
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
6
Balance: -$100
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
7
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
10
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
11
Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attributio n-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
SPRINGONE2GX
WASHINGTON, DC
Richer Data History
With Event Sourcing
Steve Pember
CTO, ThirdChannel
@svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (For Real)
• Any Tools Available?
• Demo
13
What Is Event Sourcing?
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
15
Instead, Store Facts
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
19
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
20
Event: Something Which Has
Occurred In The System
Aggregate: The Object of Events’
Affections
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
23
There is No Delete
THIRDCHANNEL @svpember
Full History of the Aggregates
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
28
THIRDCHANNEL @svpember
• snapshot photo
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
30
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
31
THIRDCHANNEL @svpember
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
34
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
• Transient Objects
35
Objects are Transient Derivatives of Your
Events
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
• Transient Objects
• Natural
38
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
40
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
41
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing
• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
• Transient Objects
• Natural
• DDD & CQRS
42
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Domain Driven Design
• Ubiquitous Language
• Bounded Context
• Domain Events
• Aggregates
• Repositories
44
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
45
–Eric Evans
“Some objects are not defined primarily by their attributes. They
represent a thread of identity that runs through time and often
across distinct representations. Sometimes such an object must
be matched with another object even though attributes differ. An
object must be distinguished from other objects even though they
might have the same attributes.”
ES & CQRS can exist separately,
but compliment each other
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Questions So Far?
• Events & Aggregates
• Snapshots
• Additive, loss-less model
• Transient Derivatives
• CQRS / DDD
49
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
50
“I Think I Get What You’re Laying
Down, But It Still Seems Bananas”
So much work!
“That’s gotta be a ton of Resource
overhead”
“Where’d my Models go? I can’t live
without my MVC!”
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing Challenges
• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
56
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing Challenges
• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
• More Storage Required VS non-ES
57
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing Challenges
• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
• More Storage Required VS non-ES
• Reduced Database Level Constraints
59
Make Use of @Transactional
Code
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing Challenges
• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
• More Storage Required VS non-ES
• Reduced Transactions / Database Level Constraints
• May Be Confusing For Junior Engineers
61
So Why Use ES?
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
63
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
64
Audit Logs Tell the History
Events Tell the Intent of History
ES is also a perfect Audit Log
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
• Data Storage is Inexpensive
68
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
• Data Storage is Inexpensive
• Used By All Long-Running Businesses
69
THIRDCHANNEL @svpember
All Business Problems Can Be Modeled
With Event Sourcing
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
• Data Storage is Inexpensive
• Used By All Long-Running Businesses
• Only Structural Model That Does Not Lose Information
73
Remember: There Is No Delete
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
• Data Storage is Inexpensive
• Used By All Long-Running Businesses
• Only Structural Model That Does Not Lose Information
• Simplified Testing and Debugging
75
Unit Test Events, Assert In Integration
Tests
Time Travel Eases Debugging
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
79
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
81
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
83
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Why Event Sourcing
• More Than an Audit Log
• Data Storage is Inexpensive
• Used By All Long-Running Businesses
• Only Structural Model That Does Not Lose Information
• Simplified Testing and Debugging
• Ideal for Business Analysis
84
Future-Proof your Data
THIRDCHANNEL @svpember
But With Event Sourcing…
–Johnny Appleseed
“Type a quote here.”
THIRDCHANNEL @svpember
Current State is a Projection
A 3C Example
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
93
Still…
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Have you ever built?
• Versioning of objects
• An ‘undo’ action
• Audit Log
• Tracking object value changes over time?
• Time series?
96
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
97
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Querying Events
• All Queries are Projections, including Current State
99
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Querying Events
• All Queries are Projections, including Current State
• Returning Current State is Easy
100
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Querying Events
• All Queries are Projections, including Current State
• Returning Current State is Easy
• Other Projections Can Be Tough, use a Read Model
102
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
103
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Querying Events
• All Queries are Projections, including Current State
• Returning Current State is Easy
• Other Projections Can Be Tough
• Try Reactive Streams
104
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
105
Use Streams to Filter Events in
Code
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
107
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Querying Events
• All Queries are Projections, including Current State
• Returning Current State is Easy
• Other Projections Can Be Tough
• Try Reactive Streams
• Initial Projection Work May Require Dev Time
108
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
109
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
110
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Theory)
• Simple Base Objects
111
Three Base Objects
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
113
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
114
Past-Tense Event Names
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
116
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Theory)
• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
117
THIRDCHANNEL @svpember
THIRDCHANNEL @svpember
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Theory)
• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
• Aggregates Receive and Play Events
120
Events Modify Aggregates
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Theory)
• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
• Aggregates Receive and Play Events
• Aggregates Require Distinction Between New and Historical Changes
123
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Theory)
• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
• Aggregates Receive and Play Events
• Aggregates Require Distinction Between New and Historical Changes
• Event Service Layer Required
125
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (Reality)
127
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Reality)
• Snapshot Rarely
128
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Reality)
• Snapshot Rarely
• ‘Pure’ Event Sourcing is tough to work with
129
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
130
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Implementation (Reality)
• Snapshot Rarely
• ‘Pure’ Event Sourcing is tough to work with
• 2 Alternatives
131
–Johnny Appleseed
“Type a quote here.”
Sync
–Johnny Appleseed
“Type a quote here.”
Plus so much more (I could talk all
day about ES)
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (For Real)
• Any Tools Available?
135
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Source Libraries
• No Real Need for an ORM
136
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Event Sourcing Libraries
• No Real Need for an ORM
• Akka Persistence (JVM)
138
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Persistence & Event Storage
• No Real Need for an ORM
• Akka Persistence (JVM)
• Database Agnostic
139
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
140
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
141
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
142
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
143
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Questions?
144
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
Agenda
• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (For Real)
• Any Tools Available?
• Demo?
145
Demo Time!
–Johnny Appleseed
“Type a quote here.”
In Summary
Event Sourcing -> Additive Only,
Lossless. Can Be Tricky To Work
With
Not for your Mom’s Blog
Thank You!
Unless otherwise indicated, these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a
Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/
THIRDCHANNEL @svpember
152
Any Questions?
Steve Pember
@svpember
www.thirdchannel.com
THIRDCHANNEL @svpember
More on Event Sourcing
• ThirdChannel Event Source Library (Java): https://github.com/RSV2/eventsource
• Demo App: https://github.com/spember/eventsource-ratpack-reference
• “Event Sourcing” (Martin Fowler): http://martinfowler.com/eaaDev/EventSourcing.html
• Event Store & “Event Sourcing Basics”: http://docs.geteventstore.com/introduction/event-sourcing-basics/
• Event Sourcing presentation by Greg Young: https://www.youtube.com/watch?v=JHGkaShoyNs
• Clarified CQRS: http://udidahan.com/2009/12/09/clarified-cqrs/
THIRDCHANNEL @svpember
Image Credits
• BOA: http://marketmadhouse.com/wp-content/uploads/2014/11/BofA.jpg
• Khaaaaan: http://d1oi7t5trwfj5d.cloudfront.net/38/0d9b80ae5311e1bcc4123138165f92/file/5-things-you-might-not-know-about-star-trek-ii-wrath-of-khan-30th-anniversary.jpg
• tribbles: http://de.memory-alpha.org/wiki/Tribble
• bank ledger: http://www.iowall.net/accounting-ledger-book.html
• ORM: https://guides.codepath.com/android/ActiveAndroid-Guide
• hoarders: http://www.aetv.com/hoarders
• snapshot stream: https://geteventstore.com/
• office space bobs: http://galleryhip.com/office-space-bobs.html
• Nye, Obama, Tyson photo: http://en.wikipedia.org/wiki/Selfie
• Printing Press: http://www.directindustry.com/prod/koenig-bauer-ag/offset-printing-presses-high-volume-40462-602574.html
• CQRS: http://udidahan.com/2009/12/09/clarified-cqrs/

Richer Data History with Event Sourcing (SpringOne 2GX 2015

  • 1.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 1 Hi.
  • 2.
  • 5.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 5 Balance: $100
  • 6.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 6 Balance: -$100
  • 7.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 7
  • 8.
  • 10.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 10
  • 11.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 11
  • 12.
    Unless otherwise indicated,these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attributio n-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ SPRINGONE2GX WASHINGTON, DC Richer Data History With Event Sourcing Steve Pember CTO, ThirdChannel @svpember
  • 13.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying • Implementation (Theory) • Implementation (For Real) • Any Tools Available? • Demo 13
  • 14.
    What Is EventSourcing?
  • 15.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern 15
  • 17.
  • 19.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 19
  • 20.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events 20
  • 21.
    Event: Something WhichHas Occurred In The System
  • 22.
    Aggregate: The Objectof Events’ Affections
  • 23.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive 23
  • 24.
  • 25.
  • 26.
    Full History ofthe Aggregates
  • 27.
  • 28.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive • Optimization: Snapshots 28
  • 29.
  • 30.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 30
  • 31.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive • Optimization: Snapshots • Example: Shopping Cart 31
  • 32.
  • 33.
  • 34.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 34
  • 35.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive • Optimization: Snapshots • Example: Shopping Cart • Transient Objects 35
  • 37.
    Objects are TransientDerivatives of Your Events
  • 38.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive • Optimization: Snapshots • Example: Shopping Cart • Transient Objects • Natural 38
  • 40.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 40
  • 41.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 41
  • 42.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing • Alternative Storage Pattern • Series of Facts • Aggregates << Events • Purely Additive • Optimization: Snapshots • Example: Shopping Cart • Transient Objects • Natural • DDD & CQRS 42
  • 44.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Domain Driven Design • Ubiquitous Language • Bounded Context • Domain Events • Aggregates • Repositories 44
  • 45.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 45
  • 46.
    –Eric Evans “Some objectsare not defined primarily by their attributes. They represent a thread of identity that runs through time and often across distinct representations. Sometimes such an object must be matched with another object even though attributes differ. An object must be distinguished from other objects even though they might have the same attributes.”
  • 48.
    ES & CQRScan exist separately, but compliment each other
  • 49.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Questions So Far? • Events & Aggregates • Snapshots • Additive, loss-less model • Transient Derivatives • CQRS / DDD 49
  • 50.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges 50
  • 51.
    “I Think IGet What You’re Laying Down, But It Still Seems Bananas”
  • 53.
  • 54.
    “That’s gotta bea ton of Resource overhead”
  • 55.
    “Where’d my Modelsgo? I can’t live without my MVC!”
  • 56.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing Challenges • Additional Work To Apply • Additional CPU Processing • Non-Traditional Concept of Models 56
  • 57.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing Challenges • Additional Work To Apply • Additional CPU Processing • Non-Traditional Concept of Models • More Storage Required VS non-ES 57
  • 58.
  • 59.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing Challenges • Additional Work To Apply • Additional CPU Processing • Non-Traditional Concept of Models • More Storage Required VS non-ES • Reduced Database Level Constraints 59
  • 60.
    Make Use of@Transactional Code
  • 61.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing Challenges • Additional Work To Apply • Additional CPU Processing • Non-Traditional Concept of Models • More Storage Required VS non-ES • Reduced Transactions / Database Level Constraints • May Be Confusing For Junior Engineers 61
  • 62.
  • 63.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It 63
  • 64.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log 64
  • 65.
    Audit Logs Tellthe History Events Tell the Intent of History
  • 67.
    ES is alsoa perfect Audit Log
  • 68.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log • Data Storage is Inexpensive 68
  • 69.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log • Data Storage is Inexpensive • Used By All Long-Running Businesses 69
  • 70.
  • 72.
    All Business ProblemsCan Be Modeled With Event Sourcing
  • 73.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log • Data Storage is Inexpensive • Used By All Long-Running Businesses • Only Structural Model That Does Not Lose Information 73
  • 74.
  • 75.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log • Data Storage is Inexpensive • Used By All Long-Running Businesses • Only Structural Model That Does Not Lose Information • Simplified Testing and Debugging 75
  • 76.
    Unit Test Events,Assert In Integration Tests
  • 77.
  • 79.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 79
  • 81.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 81
  • 83.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 83
  • 84.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Why Event Sourcing • More Than an Audit Log • Data Storage is Inexpensive • Used By All Long-Running Businesses • Only Structural Model That Does Not Lose Information • Simplified Testing and Debugging • Ideal for Business Analysis 84
  • 85.
  • 86.
  • 88.
    But With EventSourcing…
  • 89.
  • 90.
  • 91.
    Current State isa Projection
  • 92.
  • 93.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 93
  • 94.
  • 95.
  • 96.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Have you ever built? • Versioning of objects • An ‘undo’ action • Audit Log • Tracking object value changes over time? • Time series? 96
  • 97.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying 97
  • 99.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Querying Events • All Queries are Projections, including Current State 99
  • 100.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Querying Events • All Queries are Projections, including Current State • Returning Current State is Easy 100
  • 101.
  • 102.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Querying Events • All Queries are Projections, including Current State • Returning Current State is Easy • Other Projections Can Be Tough, use a Read Model 102
  • 103.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 103
  • 104.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Querying Events • All Queries are Projections, including Current State • Returning Current State is Easy • Other Projections Can Be Tough • Try Reactive Streams 104
  • 105.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 105
  • 106.
    Use Streams toFilter Events in Code
  • 107.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 107
  • 108.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Querying Events • All Queries are Projections, including Current State • Returning Current State is Easy • Other Projections Can Be Tough • Try Reactive Streams • Initial Projection Work May Require Dev Time 108
  • 109.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 109
  • 110.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying • Implementation (Theory) 110
  • 111.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Theory) • Simple Base Objects 111
  • 112.
  • 113.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 113
  • 114.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 114
  • 115.
  • 116.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 116
  • 117.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Theory) • Simple Base Objects • Aggregate and Event SubClasses Have Transient Properties 117
  • 118.
  • 119.
  • 120.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Theory) • Simple Base Objects • Aggregate and Event SubClasses Have Transient Properties • Aggregates Receive and Play Events 120
  • 121.
  • 123.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Theory) • Simple Base Objects • Aggregate and Event SubClasses Have Transient Properties • Aggregates Receive and Play Events • Aggregates Require Distinction Between New and Historical Changes 123
  • 125.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Theory) • Simple Base Objects • Aggregate and Event SubClasses Have Transient Properties • Aggregates Receive and Play Events • Aggregates Require Distinction Between New and Historical Changes • Event Service Layer Required 125
  • 127.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying • Implementation (Theory) • Implementation (Reality) 127
  • 128.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Reality) • Snapshot Rarely 128
  • 129.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Reality) • Snapshot Rarely • ‘Pure’ Event Sourcing is tough to work with 129
  • 130.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 130
  • 131.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Implementation (Reality) • Snapshot Rarely • ‘Pure’ Event Sourcing is tough to work with • 2 Alternatives 131
  • 132.
    –Johnny Appleseed “Type aquote here.” Sync
  • 133.
  • 134.
    Plus so muchmore (I could talk all day about ES)
  • 135.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying • Implementation (Theory) • Implementation (For Real) • Any Tools Available? 135
  • 136.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Source Libraries • No Real Need for an ORM 136
  • 138.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Event Sourcing Libraries • No Real Need for an ORM • Akka Persistence (JVM) 138
  • 139.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Persistence & Event Storage • No Real Need for an ORM • Akka Persistence (JVM) • Database Agnostic 139
  • 140.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 140
  • 141.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 141
  • 142.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 142
  • 143.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 143
  • 144.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Questions? 144
  • 145.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember Agenda • Event Sourcing • Event Sourcing Challenges • Don’t Worry, ES Is Worth It • Querying • Implementation (Theory) • Implementation (For Real) • Any Tools Available? • Demo? 145
  • 146.
  • 147.
  • 148.
  • 149.
    Event Sourcing ->Additive Only, Lossless. Can Be Tricky To Work With
  • 150.
    Not for yourMom’s Blog
  • 151.
  • 152.
    Unless otherwise indicated,these slides are © 2013 -2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ THIRDCHANNEL @svpember 152 Any Questions? Steve Pember @svpember www.thirdchannel.com
  • 153.
    THIRDCHANNEL @svpember More onEvent Sourcing • ThirdChannel Event Source Library (Java): https://github.com/RSV2/eventsource • Demo App: https://github.com/spember/eventsource-ratpack-reference • “Event Sourcing” (Martin Fowler): http://martinfowler.com/eaaDev/EventSourcing.html • Event Store & “Event Sourcing Basics”: http://docs.geteventstore.com/introduction/event-sourcing-basics/ • Event Sourcing presentation by Greg Young: https://www.youtube.com/watch?v=JHGkaShoyNs • Clarified CQRS: http://udidahan.com/2009/12/09/clarified-cqrs/
  • 154.
    THIRDCHANNEL @svpember Image Credits •BOA: http://marketmadhouse.com/wp-content/uploads/2014/11/BofA.jpg • Khaaaaan: http://d1oi7t5trwfj5d.cloudfront.net/38/0d9b80ae5311e1bcc4123138165f92/file/5-things-you-might-not-know-about-star-trek-ii-wrath-of-khan-30th-anniversary.jpg • tribbles: http://de.memory-alpha.org/wiki/Tribble • bank ledger: http://www.iowall.net/accounting-ledger-book.html • ORM: https://guides.codepath.com/android/ActiveAndroid-Guide • hoarders: http://www.aetv.com/hoarders • snapshot stream: https://geteventstore.com/ • office space bobs: http://galleryhip.com/office-space-bobs.html • Nye, Obama, Tyson photo: http://en.wikipedia.org/wiki/Selfie • Printing Press: http://www.directindustry.com/prod/koenig-bauer-ag/offset-printing-presses-high-volume-40462-602574.html • CQRS: http://udidahan.com/2009/12/09/clarified-cqrs/

Editor's Notes

  • #3 Before I begin, I just want to run through a quick scenario with you all
  • #4 Picture your bank in your mind. For many of us, this may not exactly be a happy thought. There’s likely several brick and mortar branches for your particular bank in the area. However, being tech folks, I don’t suppose it’s a stretch to surmise that you all primarily interact with your bank via their website, yes?
  • #5 Imagine you went to your bank’s wonderful website, entered your information, and logged in successfully. I hope no one works for farmers. I typed in “Bank website” into google, and this was the first result.
  • #6 And, upon logging in, you click the link to check your balance. In doing so, you’re presented with a screen that just shows you “Balance, $100”, but with no context around that number. This may be fine if you expected there to be $100…
  • #8 What if that’s all your bank balance was, just a simple number? What if that was all your bank could tell you? What if your balance was simply a column in a row in a database somewhere? … and What if you didn’t agree?
  • #9 How angry would you be? Can you imagine the arguments you’d have with the teller or an agent over the phone, trying to figure out if your latest pay check was deposited?
  • #10 Luckily, that’s not how things are done. Banks store your account’s entire history. Every transaction you make with your bank. Every Credit or Debit made is logged, along with an audit trail of who (e.g. which teller) made the change. To get your balance, your bank simply adds up each of these transactions May also periodically record what the balance was at specific points in time, to prevent having to recalculate everything from the beginning of time.
  • #11 There’s a certain advantage to this idea, that we can record all modifications to our data - in this case, the credits and the debits - as EVENTS that occur within our system. For example, Your bank is able to tell you exactly how they arrived at your account balance.
  • #12 -What about your company’s software? -Can you tell your users or internal business analysts how you are arriving at the data your application presents to them? If they have a disagreement with a value in a … -Today I’m going to present a method called Event Sourcing that does just… that and how it can fuel the competitiveness of your company.
  • #13 Bold, right? With that, this is ‘Richer Data History with Event Sourcing’. My name is Steve, and I work for a startup called ThirdChannel, which is located in Boston
  • #14 Today I’d like to go over the following topics: -Event Sourcing at a high level, -Challenges - Querying: “How do I query this mess?”
  • #15 Let’s begin
  • #17 Or rather, it’s alternative to your standard ORM storage mapping, Where an object in memory maps directly to a row in a database, even if that row may be split via joins * update is made to a model, updates a column in your database * in this method, the only thing you know about your data is what it looks like right now.
  • #18 Event Sourcing says “that’s fine, but we’re going to something a bit different”. Instead of storing the current state of our models, we’re going to store facts about our models
  • #19 Every successful user interaction generates a series of facts or ‘events’ within our system
  • #20 This stream of events are persisted in our database in the order they occurred, as a journal of what has transpired. These events can then be played back against our Domain Object, building it up to the state it would be at any given point in time, although this is most likely the Current State A stream of events represent a particular object in Aggregate
  • #21  Which means I should talk about the two main concepts behind Event Sourcing
  • #22 An Event Represents something that has occurred within your system. The past tense is important when describing them. It represents an intentional user action or result of user action that almost always results in the manipulation or state change or an Object. Things like “BankAccountOpened”, “CurrencyDeposited” are decent names for events
  • #23 The objects which are affected by Events are referred to as an Aggregate. They generally serve as a root for a stream of events; they represent the state of an event stream ‘in aggregate’. If it helps, you can think of it like a domain model. It doesn’t have to be, though. It can be, say, relationships between objects. For example, at ThirdChannel we model the assignment relationship between our users and what we call programs as an Aggregate. Along with many other things. Note this is a very simple explanation, and I’ll touch more on this later
  • #24 Event Sourcing is a purely additive model…
  • #25 there are no deletes or updating of events. Events are immutable once written to our journal This is a powerful notion, if you consider the implications: using Event Sourcing, no data is ever lost or ignored. <pause>
  • #26 Now, When I need to retrieve information about my Aggregates, I simply play back all of the events that have occurred in the past in order to build up the data to a specific point in time, generally the current date, thus getting the current state of our data.
  • #27 One of the Key points: by maintaining all events, we’re able to access the current state of our aggregates (again, or objects), certainly, but we can also access the state of our data or aggregates at any point in time. Which is huge.
  • #28 Now, I’m sure some of you are thinking “waiiit, if I never get rid of anything, certainly that has tradeoffs, too?” Specifically, performance. What happens if I have thousands, or even millions of events I have to apply?
  • #29 You’re right, and that’s a great observation. Luckily, Event Sourcing recommends an early optimization known as ‘Snapshots’
  • #30 A Snapshot is just what you’d think it would be: a recording of the details of your Aggregate at that moment in time. Persisted forever
  • #31 As we consume and create events, periodically we persist a snapshot, containing the state of the aggregate at that point in time. -When replaying events, we load from the most recent snapshot, then apply only the events between when that snapshot was taken, and the targeted end date. So, in this case,… -I’ll get into some more specifics around snapshots in a bit.
  • #32 One of my favorite examples
  • #33 Suppose we were building an ecommerce app and we are building the ‘shopping’ cart feature.
  • #34 Naive, ORM, relational -> join table with quantity Event Sourcing -> <identify page components> are not saved as a join table or a single row.
  • #35 Instead, w/ ES, system stores all commands you’ve issued / replays for current state <list events> Quickly remove base from the cart, before placing the order and generating an OrderPlacedEvent View doesn’t display raw events Data backing the view is built up from events to form an Object intended for View For those of you familiar with ‘CQRS’, ES is commonly featured as part of it; I’m attempting to describe the ‘Read’ component. Object is Transient -> object will be garbage collected and no direct representation exists on disk
  • #36 That brings up the next step, Working with Objects
  • #37 And this is where Event Sourcing will start to hurt your brain. In order to fully grasp what Event Sourcing is, it’s important to realize that…:
  • #38 All objects that are ‘displayed’ to the user in your View layer are simply transient derivatives of your event stream. They are ephemeral and must be built up from the events to be used in a traditional manner within your application
  • #39 Finally, I argue that structuring our data in this way is akin to the way our brains work; it’s natural.
  • #40 Internally, your mind is able to tell you the current state of your knowledge about things. This current state is formed by a series of observations / facts / events in your past. You’re able to replay these events in your mind, and also remember your knowledge at that point in time. Our minds aren’t perfect, though, and sometimes we violate the ES rules by deleting Events. Ooops.
  • #41 Let’s take me as an Example. Even if you’ve never seen or met me before today, your mind has already recorded a series of facts which is driving your mental model of me. For example: FeatureObservedEvent ActionObservedEvent -Now, if I were to suddenly make a rude gesture at the audience…
  • #42 that would apply a new event to your mental model. Your current state opinion of me would likely be negative although you could remember a time before you thought negatively of me. “Man, Steve seemed like an alright guy until he flipped off the audience. What a jerk”
  • #43 Finally, I would be remiss if I didn’t mention Domain Driven Design or CQRS while standing up here talking about Event Sourcing
  • #44 Has anyone read? Domain Driven Design by Eric Evans?      - Eric wrote this book after years of trying to create  enterprise software      - some great concepts in there…
  • #45  -Ubiquitous Language -> the domain model the engineers build should be handed down from domain experts. Both the business side of things and the engineers should be able to talk about the system using the same terms and languages. In other words, your engineers should never say ‘AbstractFactory’ to your designers.      -Bounded Context -> keep related models isolated and segregated from the others      -Domain events - something that occurs that domain experts care about      -Aggregates      -Repositories -> each domain object or bounded context should have a dedicated repository for accessing its storage
  • #46 Earlier I mentioned that you could think of an Aggregate as equivalent to a domain object or an entity… and while you can, the concept of an Aggregate is expressed a bit different in DDD. An Aggregate can be comprised of several ‘internal’ objects which are owned by a ‘parent’ object. This parent object is known as the Aggregate Root. External code touches the Root Aggregate, but cannot link to the Root’s supporting objects
  • #47 One of the most interesting parts of DDD, one that really stuck with me, is this quote: <read quote> - that’s interesting, yeah?                If I change my name, am I no longer me? Of course not, I’m defined by more than my name. If I change my email address, or my address, or my social security number for some reason, am I no longer me? Obviously not… Can your database understand identity changes like this and still be able to find the original object?                I think this is the heart of Event Sourcing.
  • #48 not going to spend too much time on this, as CQRS could be it’s own session. I believe there’s a full session dedicated to CQRS later in the conference, so if this seems intriguing, please go. Commands vs Queries      - Write and Read Requests are handled by different objects and different routines within your system. Actual POGO or POJO objects encapsulating your incoming commands and the outing reads      - Ideally, different data repositories      - Event Sourcing tends to go hand in hand with CQRS
  • #49 -as we’ll see later, some of the terms overlap - in this talk, I explicitly focus on ES, as I think it has a greater
  • #50 That, I think, is the basis for what Event Sourcing is. It may be a bit early, but are there any questions so far?
  • #51 Then Let’s move on to the next section, Challenges or Difficulties with ES. Or as I like to call it…
  • #53 Right now, you may be suspicious. You may be thinking:
  • #54 “I mean, what you’re describing sounds like a ton of extra work to implement.”
  • #55 -Not to mention a ton of overhead in processing these events, even if we do make good use of these snapshots you mention
  • #56 How can you operate in a world without Models?!
  • #57 And yes, that’s true. *pause* Furthermore, here’s some more bad things:
  • #58 Storing every event that occurs within your system will almost certainly require more storage space
  • #59 your database is going to start looking a bit cluttered, and you will repeatedly ask yourself why the heck you keep all this stuff around… who’s going to back and look at all those old books anyway?
  • #60 Now this is a truly difficult one. - Will have reduced Database Level Constraints, like Foreign Keys, null checks, unique checks, etc. - Instead, we have to rely on our software for transactions and these database constraints
  • #61 -This is usually where I lose the more seasoned developers. -Because our properties tend to be transients, serialized within the event, we lose things like foreign key constraints at the db level -Instead, in Event Sourcing, these checks tend to move within Transactional blocks within your code. If you’re using Grails or Spring, just slap on an @Transactional annotation
  • #62 Finally… ES can also be difficult for Junior Engineers I’ve noticed that people really cling to the Model View Controller way of life. - This is a very different way of building our applications, particularly for the web Recommending a different structure for the Model can make people wary. - Telling people that their Views become a “Transient object derived from the event stream” scares them
  • #63 As crazy as this all might sound, I argue that Event Sourcing actually has huge Benefits
  • #64 Next Up, “don’t worry, ES is worth it”
  • #65 First, Going back to the concept of a transaction or an Audit Log… Why is it that I’d want something fancy like ES, when I can audit a log file or look at my transaction log?
  • #66 There’s a subtle difference between an Audit Log and an Event Stream. Audit logs tell the history of what happened in your system or what was persisted to the database. Events Tell
  • #67 Furthermore, Having the Events as a first-order member of your platform can give you enhanced information around what your users or systems are doing beyond what might normally get written to the database. Can make events that don’t necessarily deal with the properties changed by a user, but additional actions that may have occurred And it’s easier to work with and analyze the data if the events are integrated within your platform already.
  • #68 Incidentally, an event object typically should have attached to it information about the user which generated the event, which also makes ES a perfect Audit Log
  • #69 Data storage is crazy cheap. Last I looked, AWS basic SSD storage was 0.013 per gigabyte hour/ which equates to… If you’re at the point where those pennies matter, you probably have bigger problems.
  • #70 next. What I find interesting is that Event Sourcing, or a non-digital analogue of it, is used by every ‘mature’, or long running business.
  • #71 Just Like I went over in the beginning, banks and accounting methods operate with Event Sourcing Bankers additionally even use snapshots of your balance in an additional column beyond credits and debits
  • #72 Lawyers! If a contract needs to be adjusted, is the contract thrown out and re-written? No. Rather, ‘addendums’ are placed on the contract. To figure out the contract actually involves, one has to read the initial contract, and then each successful addendum in order to figure out what the thing actually says.
  • #73 In addition, all business problems can be successfully modeled with - and benefit greatly by - event sourcing
  • #74 How many of you all have delete statements in your code? Even if you don’t, every time you update a row in a database and overwrite some column, you’ve just lost information
  • #75 Remember: there is no delete, ES is the only structural model which does not lose information.
  • #76 Event Sourcing simplifies Testing and Debugging. A bold claim, I know.
  • #77 Testing is easier / simplified with ES, you unit test the events, then later you can simply assert that specific events are applied during integration testing
  • #78 In addition, debugging is easy, because we have the entire history of our data.
  • #79 We can look back through our Aggregates’ timelines <next> and examine them at any point in history.
  • #80 Thus I can see what the historical state of the aggregate… or all my aggregates… was at a particular point in time, along with how it reached that state and who caused those changes.
  • #81 ahem… I’m sure you’re all keenly aware, but 2015 is the year they visited in this movie. “Where’s my Hoverboard?!” Anyway. If we at some point note that there’s an error or discrepancy in our data…
  • #82 debugging or tracing the error is a snap -We can find the faulty or conflicting event, know who executed it, when they executed it, and what lead up to the bad state. And then we can emit a new event to ‘patch’ the issue
  • #83 If we want to get even crazier, we could go to a specific point in our data’s timeline, then fire fake events in order to simulate alternate timelines.
  • #84 pause This has interesting applications for, say, a.b. testing, stress, and disaster testing. If any of these past few slides reminds you of git… well, how astute. Git is like recursive event sourcing. Ever look at the reflog?
  • #85 Event sourcing is the ideal storage mechanism for business analysis
  • #86 -because Event Sourced systems do not lose data, they’re future proofed against any crazy reports that your business analysts may need in the future
  • #87 suppose one such analyst came to your Ecommerce / shopping cart team asking for… all shoppers who add items to their cart and then remove them within 5 minutes. They want to know who, and which products
  • #88 with non es, and the naive way I mentioned earlier, you might have to build some sort of tracking table, or mark additional rows with a timestamp.. I dunno. Regardless, then you deploy… and then wait for the data to gather, as users add and remove products
  • #89 with Event Sourcing, your write a query for that report, you deploy… and then what to do you have? If you’re thinking: all of the data, obviously… well, you’re wrong. You have MORE than everything. We can generate the report for how it would look at every point in our history.
  • #90 Which makes the company and your business analysts extremely happy. There’s nothing they like better than a good report.
  • #91 Querying over the events; presenting different Views on them, is often called a projection Perhaps the biggest advantage of ES for me. look at specific events across one stream look at specific event types across all streams I don’t have to query on properties of our domain objects… we can look for patterns in our event stream.
  • #92 Grabbing the Current State of an aggregate is a projection, and probably the easiest: take all events for an Aggregate, in order. There’s a good deal else to find. In our shopping cart example: find items in cart for any given date or time range find items that were removed for any given date or time range find average rate of items removed vs items purchased for any given… find average duration between items being added and then being removed for any…
  • #94 Model the relation between our users and the role and state within our platform Can certainly tell you All of the current FMRs or Agents which one of us made those transitions a timeline of each agent’s transition within the program applications with a long gap between entering the system and being wait listed or interviewed, to see how long a candidate waits until we contact them how long on average, an agent lasts before being fired and/or average time for agents that have quit Turnover for a date range And I can tell you that information at ANY POINT IN TIME. e.g. the average quit rate might be different now than 6 months ago, for example that’s all I could think of off the top of my head Which is amazing, right? Just from that one relation. What would happen.. if I started to correlate other event streams?
  • #95 <Pause> Even after this presentation, if you’re still skeptical of the benefits… and you think this is the silliest thing you’ve ever heard of
  • #96 ..be aware that the decision can be out of your hands. Event Sourcing is often chosen or driven by Management out of business needs, and ‘hacky’ analogues are shoehorned into an existing system AFTER the fact.
  • #97 I know I have
  • #98 And now we get to a particular hairy topic…
  • #99 How am I going to handle all of these events and find what I’m looking for?
  • #100 All queries within ES are often referred to as a Projections over the Event Stream. This includes the concept of the current state.
  • #101 Returning the current state of your aggregates is easy. In other words, a lookup by Id is simple.
  • #102 Load the aggregate or aggregates by id, load all of the events and replay the events to get back to current state Fairly easy and straightforward
  • #103 All queries within ES are often referred to as a Projection over the Event Stream. This includes the concept of the current state. Typically when working with relational data, we’ll either say something like “get me the object Foo with id x”, which maps well to the current state of an object.
  • #104 But not so much with Events, get to this in a minute, but an event is difficult to query Queries like “Find all Foos with active=true and date between 2 values” is easy in standard ‘normal’ form databases. One alternative is a read model maintain a synchronized copy of your aggregates in another table; always sync current state into it, and then query that table Analogous to a database ‘View’ I generally like to keep any data synchronization to a minimum, but this approach can be an attractive convenience for current state searches
  • #108 In fact, the Event Store database, that’s exactly what they do. One has to write Projections using Streams within a web interface, that then become query-able by clients.
  • #109 However, as you can probably see. This is fairly difficult. The development team will need to spend time writing the projections. If you have analysts on your team that are used to writing sql, well, it’s going to be much more difficult for them.
  • #110 Consider feeding events into additional services or tools, particularly those that are stream friendly, like Splunk or Apache Storm
  • #111 first let’s discuss the theoretical approaches.
  • #112 Pure Event Sourcing is fairly simplistic in terms of implementation
  • #113 There’s really only 3 base objects that you have to worry about.
  • #114 -First up, the Aggregate. You have the id, which should be a UUID, the current revision number, and the type (or ‘clazz’ if you’re working with java) -The current revision number is used for optimistic locking and to see how advanced our aggregate is. -The type is used by our system when we want to load the aggregate into a more meaningful class in the system, say, a SubClass of Aggregate. In our example, the ShoppingCart class would SubClass from Aggregate
  • #115 Next up, Event -id, revision aggregate_id, the date with time stamp, the type, the user id, and then ‘data’ -data is a serialized representation of the event type’s properties. Generally, JSON, XML, or are recommended for the storage mechanism in the data column. - this could also be a more efficient mechanism, too, like Google’s Protocol Buffers or Apache Avro
  • #116 All Events should be named in the past tense, as they should reflect something successful that happened in the PAST
  • #117 Lastly, we have Snapshot. Again, we want to serialize the properties of the aggregate at that moment in time. Next,
  • #118 I should be clear about what - exactly - is being serialized into those data fields. Aggregates and Events, or at least classes that implement Aggregate and Event, contain, themselves, transient properties which are generally not persisted to the database.
  • #119 Plain old object with explicit transient properties each has corresponding event or events
  • #120 The Event itself has transient properties, whose values are persisted to the database. Also, if anyone notices that I’m using JPA annotations and I earlier mentioned that this is an alternative to ORMs… appreciate the irony. This is from a small demo app.
  • #122 Events Modify Transient values on the Aggregate
  • #123 It’s almost a Visitor pattern. As Events are generated, they are applied to an Aggregate. Aggregates are built up or, in the case of loading an aggregate, building back up. Event by Event my actual aggregate class may have several properties, however, they are all transient, in the sense that they are not persisted local to the aggregate… e.g. not in the same table. When the aggregate is first created, all of these transients are at their default value, and the playback of the events will restore them to whichever point in time I want.
  • #125 shopping cart -> Order placement should only charge credit card the first time the event is created
  • #126 In addition, you’ll also need a service layer to store and load the events and aggregates
  • #127 it must remember to load events in order of their revision number for the correct aggregate, and initiate the event serialization and de-serialization processes
  • #128 And those are the basics. That’s not too bad, eh? Unfortunately… there are a few more practical considerations to go over that are a reality for any real ES system.
  • #129 While snapshots seem awesome, do it only rarely. Greg Young, one of the largest voices in the ES community, claims that he doesn’t snapshot an aggregate until it reaches 1000 events. You have to juggle the time cost of the additional query for the snapshot versus the processing of the small event objects.
  • #130 While snapshots seem awesome, do it only rarely. Greg Young, one of the largest voices in the ES community, claims that he doesn’t snapshot an aggregate until it reaches 1000 events. You have to juggle the time cost of the additional query for the snapshot versus the processing of the small event objects.
  • #131 I internally made this slide hard to read to emphasize the point: querying for specific properties within events is tough. See that nice blob of JSON in the data column? As an aside: We use Postgres, which I love, which has two dedicated types for working with JSON. However, I also love JOOQ and JPA, both of which can not work with those types. If anyone knows of a way to get those working with Postgres JSON, please let me know.
  • #132 While snapshots seem awesome, do it only rarely. Greg Young, one of the largest voices in the ES community, claims that he doesn’t snapshot an aggregate until it reaches 1000 events. You have to juggle the time cost of the additional query for the snapshot versus the processing of the small event objects.
  • #133 First, the ‘Synced’ pattern. This involves keeping a ‘standard’ synchronized, current state representation of your aggregates. All writes go into the Event log, and then the Domain object is updated. All queries done against the ‘standard’ Domain objects. This is a read model Downside is that you have to do an additional write in sync with your event stream, which can be a pain.
  • #134 Second, and my preferred pattern, is what I call the ‘Hybrid’ approach   Use multi table inheritance to give each of your aggregates their own table. Add each of the properties you’d like to index or add database level checks, like foreign keys. It doesn’t have to be all the properties. Your aggregate maintains the current state of your data at the db level Now, the advantage of this approach is that I get the benefits of both ES and standard relational. I can make use of the standard relational db querying and indexing, plus each of my aggregates is backed by the event journal
  • #135 I had originally built this out to enumerate many more items, but then realized that they could be grouped into distinct sections. So, next up…
  • #138 With the naive use case, here’s my entire schema… our at least, without Snapshot. The snapshot is very similar to aggregate, just with a data text field
  • #139 These are the ones I’m aware of that are in active development. NVentStore, Prooph, and Akka. Akka is interesting, in that every object you work with is persisted as an event stream, but it doesn’t explicitly call itself Akka Event Source. Of these, I’d probably recommend Akka, provided you’re on the JVM. The persistence component is available as a standalone jar
  • #140 When looking for a storage mechanism, there many options available to you, and, for the most part, you’ll be fine no matter which database option you choose. Now, here are some of the better options
  • #141 First, EventStore, the database. Highly specialized for working with events and generating projections. Written By Greg Young, who is perhaps the most well known person in the Event Sourcing community.
  • #142 A time series database like influxDB is a great choice as an event store
  • #143 Chiefly intended as a message broker, it also maintains a journal of all your events. I haven’t used it directly, but anytime I start talking about Event Sourcing, someone mentions Kafka. I should really check it out.
  • #144 And if course, you cannot go wrong with good, old fashioned Relational Databases. I would suggest consider sticking with a standard relation database, if you’re already using it Switching to something like Event Sourcing is already enough change A quick aside.
  • #148 First, I’d like to point out that we at ThirdChannel have open sourced a small library that we’re using internally for doing Event Sourcing on the JVM. written in Groovy and RxJava
  • #150 Event Sourcing is an additive only, lossless data storage pattern which has insanely high potential for data analysis. It is, however, tricky to work efficiently with.
  • #151 I wouldn’t recommend it for certain applications; say small static content information websites (e.g. a restaurant or a business’ marketing site). Nor does it make sense to apply to every domain object in a system. However, key data in your application that you use to drive your business can benefit greatly from this approach.
  • #152 With that, I say thank you for you coming.