THIRDCHANNEL @svpember Hi.
Aug 17, 2015
THIRDCHANNEL @svpember
Richer Data History With Event Sourcing
Steve PemberCTO, ThirdChannelgr8Conf US 2015
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 (Hopefully)
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
• Transient Objects
THIRDCHANNEL @svpember
Event Sourcing• Alternative Storage Pattern
• Series of Facts
• Aggregates << Events
• Purely Additive
• Optimization: Snapshots
• Example: Shopping Cart
• Transient Objects
• Natural
THIRDCHANNEL @svpember
Questions So Far?• Events & Aggregates
• Snapshots
• Additive, loss-less model
• Transient Derivatives
THIRDCHANNEL @svpember
Event Sourcing Challenges• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
THIRDCHANNEL @svpember
Event Sourcing Challenges• Additional Work To Apply
• Additional CPU Processing
• Non-Traditional Concept of Models
• More Storage Required VS non-ES
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
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
THIRDCHANNEL @svpember
Agenda• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
THIRDCHANNEL @svpember
Why Event Sourcing• More Than an Audit Log
• Data Storage is Inexpensive
• Used By All Long-Running Businesses
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
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
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
THIRDCHANNEL @svpember
Have you ever built?• Versioning of objects
• An ‘undo’ action
• Audit Log
• Tracking object value changes over time?
• Time series?
THIRDCHANNEL @svpember
Agenda• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
THIRDCHANNEL @svpember
Querying Events• All Queries are Projections, including Current State
• Returning Current State is Easy
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
THIRDCHANNEL @svpember
Querying Events• All Queries are Projections, including Current State
• Returning Current State is Easy
• Other Projections Can Be Tough
• Try Reactive Streams
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
THIRDCHANNEL @svpember
Agenda• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
THIRDCHANNEL @svpember
Implementation (Theory)• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
THIRDCHANNEL @svpember
Implementation (Theory)• Simple Base Objects
• Aggregate and Event SubClasses Have Transient Properties
• Aggregates Receive and Play Events
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
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
THIRDCHANNEL @svpember
Agenda• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (Reality)
THIRDCHANNEL @svpember
Implementation (Reality)• Snapshot Rarely
• ‘Pure’ Event Sourcing is tough to work with
THIRDCHANNEL @svpember
Implementation (Reality)• Snapshot Rarely
• ‘Pure’ Event Sourcing is tough to work with
• 2 Alternatives
THIRDCHANNEL @svpember
Agenda• Event Sourcing
• Event Sourcing Challenges
• Don’t Worry, ES Is Worth It
• Querying
• Implementation (Theory)
• Implementation (For Real)
• Any Tools Available?
THIRDCHANNEL @svpember
Persistence & Event Storage• No Real Need for an ORM
• Akka Persistence (JVM)
• Database Agnostic
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?
THIRDCHANNEL @svpember
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/event-source-demo• “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
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