richer data-history-event-sourcing

Post on 14-Jul-2015

375 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

THIRDCHANNEL

Hi.

First, A Quick Scenario

THIRDCHANNEL

Balance: $100

THIRDCHANNEL

Balance: -$100

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

Richer Data History With Event

Sourcing

Steve Pember

CTO, ThirdChannel

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

• Implementation (Reality)

• Event Storage

• Querying

• Demo

What Is Event Sourcing?

THIRDCHANNEL

Event Sourcing• Alternative Storage Pattern

THIRDCHANNEL

Instead, Store Facts

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

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

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

There is No Delete

THIRDCHANNEL

Full History of the Aggregates

THIRDCHANNEL

THIRDCHANNEL

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

THIRDCHANNEL

• snapshot photo

THIRDCHANNEL

THIRDCHANNEL

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

• Example: Shopping Cart

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

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

Event Sourcing• Alternative Storage Pattern

• Series of Facts

• Aggregates << Events

• Purely Additive

• Optimization: Snapshots

• Example: Shopping Cart

• Transient Objects

• Natural

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

Questions So Far?• Events & Aggregates

• Snapshots

• Additive, loss-less model

• Transient Derivatives

THIRDCHANNEL

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 CPU overhead”

“Where’d my Models go? I can’t live without my

MVC!”

THIRDCHANNEL

Event Sourcing Challenges• Additional Work To Apply

• Additional CPU Processing

• Non-Traditional Concept of Models

THIRDCHANNEL

Event Sourcing Challenges• Additional Work To Apply

• Additional CPU Processing

• Non-Traditional Concept of Models

• More Storage Required VS non-ES

THIRDCHANNEL

THIRDCHANNEL

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

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

THIRDCHANNEL

So Why Use ES?

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

THIRDCHANNEL

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

Why Event Sourcing• More Than an Audit Log

• Data Storage is Inexpensive

THIRDCHANNEL

Why Event Sourcing• More Than an Audit Log

• Data Storage is Inexpensive

• Used By All Long-Running Businesses

THIRDCHANNEL

All Business Problems Can Be Modeled With

Event Sourcing

THIRDCHANNEL

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

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

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

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

But With Event Sourcing…

–Johnny Appleseed

“Type a quote here.”

THIRDCHANNEL

Current State is a Projection

A 3C Example

THIRDCHANNEL

Still…

THIRDCHANNEL

THIRDCHANNEL

Have you ever built?• Versioning of objects

• An ‘undo’ action

• Audit Log

• Tracking object value changes over time?

• Time series?

THIRDCHANNEL

Questions so far?

Next Up: Implementation

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

THIRDCHANNEL

Implementation (Theory)• Simple Base Objects

Three Base Objects

THIRDCHANNEL

THIRDCHANNEL

Past-Tense Event Names

THIRDCHANNEL

THIRDCHANNEL

Implementation (Theory)• Simple Base Objects

• Aggregate and Event SubClasses Have Transient Properties

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

Implementation (Theory)• Simple Base Objects

• Aggregate and Event SubClasses Have Transient Properties

• Aggregates Receive and Play Events

Events Modify Aggregates

THIRDCHANNEL

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

THIRDCHANNEL

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

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

• Implementation (Reality)

THIRDCHANNEL

Implementation (Reality)• Freely Add New Transient Properties

THIRDCHANNEL

Implementation (Reality)• Freely Add New Transient Properties

• Be Wary of Modifying Events

THIRDCHANNEL

Implementation (Reality)• Freely Add New Transient Properties

• Be Wary of Modifying Events

• Be Wary of Removing Aggregate Transients

THIRDCHANNEL

Implementation (Reality)• Freely Add New Transient Properties

• Be Wary of Modifying Events

• Be Wary of Removing Aggregate Transients

• Snapshot Rarely

Plus so much more…

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

• Implementation (Reality)

• Persistance

THIRDCHANNEL

Persistence & Event Storage• No Real Need for an ORM

THIRDCHANNEL

THIRDCHANNEL

Persistence & Event Storage• No Real Need for an ORM

• Try a Library

THIRDCHANNEL

Event Sourcing Libraries• NEventStore (.NET)

• ProophEventStore (PHP)

• Akka Persistence (JVM)

THIRDCHANNEL

Persistence & Event Storage• No Real Need for an ORM

• Try a Library

• Database Agnostic

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

THIRDCHANNEL

Persistence & Event Storage• No Real Need for an ORM

• Database Agnostic

• Consider Using a Relational DB

THIRDCHANNEL

Questions?

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

• Implementation (Reality)

• Persistance

• Querying

THIRDCHANNEL

Querying Events• All Queries are Projections, including Current State

THIRDCHANNEL

Querying Events• All Queries are Projections, including Current State

• Returning Current State is Easy

THIRDCHANNEL

THIRDCHANNEL

Querying Events• All Queries are Projections, including Current State

• Returning Current State is Easy

• Other Projections Can Be Tough

Query across Event Types

THIRDCHANNEL

THIRDCHANNEL

Querying Events• All Queries are Projections, including Current State

• Returning Current State is Easy

• Other Projections Can Be Tough

• Try Reactive Streams

THIRDCHANNEL

Use Streams to Filter Events in Code

THIRDCHANNEL

THIRDCHANNEL

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

Find Someone with a Statistics

Background

THIRDCHANNEL

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

• Consider Cacheable Query Layers

Separate Event Storage / Querying

Services

THIRDCHANNEL

THIRDCHANNEL

Agenda• Event Sourcing

• Event Sourcing Challenges

• Don’t Worry, ES Is Worth It

• Implementation (Theory)

• Implementation (Reality)

• Persistance

• Querying

• Demo Time

Pray to the demo gods.

THIRDCHANNEL

In Summary

Event Sourcing -> Additive Only,

Lossless. Can Be Tricky To Work With

Not for your Mom’s Blog

Thank You!

THIRDCHANNEL

Any Questions?

Steve Pember

@svpember

www.thirdchannel.com

THIRDCHANNEL

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

top related