+ All Categories
Home > Software > Gr8conf US 2015 - Intro to Event Sourcing with Groovy

Gr8conf US 2015 - Intro to Event Sourcing with Groovy

Date post: 17-Aug-2015
Category:
Upload: steve-pember
View: 469 times
Download: 0 times
Share this document with a friend
Popular Tags:
146
THIRDCHANNEL @svpember Hi.
Transcript

THIRDCHANNEL @svpember

Hi.

First, A Quick Scenario

THIRDCHANNEL @svpember

Balance: $100

THIRDCHANNEL @svpember

Balance: -$100

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

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)

What Is Event Sourcing?

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

THIRDCHANNEL @svpember

Instead, Store Facts

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

Event: Something Which Has Occurred In The System

Aggregate: The Object of Events’ Affections

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

There is No Delete

THIRDCHANNEL @svpember

Full History of the Aggregates

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

THIRDCHANNEL @svpember

• snapshot photo

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

• Example: Shopping Cart

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

• Example: Shopping Cart

• Transient Objects

Objects are Transient Derivatives of Your Events

THIRDCHANNEL @svpember

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

• Example: Shopping Cart

• Transient Objects

• Natural

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Questions So Far?• Events & Aggregates

• Snapshots

• Additive, loss-less model

• Transient Derivatives

THIRDCHANNEL @svpember

Agenda• Event Sourcing

• Event Sourcing Challenges

“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!”

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

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

Make Use of @Transactional Code

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

So Why Use ES?

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

Audit Logs Tell the History

Events Tell the Intent of History

ES is also a perfect Audit Log

THIRDCHANNEL @svpember

Why Event Sourcing• More Than an Audit Log

• Data Storage is Inexpensive

THIRDCHANNEL @svpember

Why Event Sourcing• More Than an Audit Log

• Data Storage is Inexpensive

• Used By All Long-Running Businesses

THIRDCHANNEL @svpember

All Business Problems Can Be Modeled With Event Sourcing

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

Remember: There Is No Delete

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

Unit Test Events, Assert In Integration Tests

Time Travel Eases Debugging

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

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

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

THIRDCHANNEL @svpember

Still…

THIRDCHANNEL @svpember

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

THIRDCHANNEL @svpember

Querying Events• All Queries are Projections, including Current State

• Returning Current State is Easy

THIRDCHANNEL @svpember

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

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

Use Streams to Filter Events in Code

THIRDCHANNEL @svpember

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

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

Three Base Objects

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Past-Tense Event Names

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Implementation (Theory)• Simple Base Objects

• Aggregate and Event SubClasses Have Transient Properties

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Implementation (Theory)• Simple Base Objects

• Aggregate and Event SubClasses Have Transient Properties

• Aggregates Receive and Play Events

Events Modify Aggregates

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

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

THIRDCHANNEL @svpember

Implementation (Reality)• Snapshot Rarely

• ‘Pure’ Event Sourcing is tough to work with

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Implementation (Reality)• Snapshot Rarely

• ‘Pure’ Event Sourcing is tough to work with

• 2 Alternatives

THIRDCHANNEL @svpember

Sync

THIRDCHANNEL @svpember

Plus so much more (I could talk all day about ES)

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

Event Source Libraries• No Real Need for an ORM

THIRDCHANNEL @svpember

Event Sourcing Libraries• No Real Need for an ORM

• Akka Persistence (JVM)

THIRDCHANNEL @svpember

Persistence & Event Storage• No Real Need for an ORM

• Akka Persistence (JVM)

• Database Agnostic

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Questions?

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?

Demo Time!

THIRDCHANNEL @svpember

In Summary

Event Sourcing -> Additive Only, Lossless. Can Be Tricky To Work

With

Not for your Mom’s Blog

Thank You!

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


Recommended