introduction to event sourcing

23
Introduction to Event Sourcing and Read-Model Projections Jeffrey T. Fritz @csharpfritz http://csharpfritz.com

Upload: jeffrey-t-fritz

Post on 01-Jul-2015

172 views

Category:

Technology


2 download

DESCRIPTION

Presentation slides from sessions discussing Event Source data storage and read-model projections. Source code from demos at: https://bitbucket.org/csharpfritz/nerddinner-cqrs

TRANSCRIPT

Page 1: Introduction to Event Sourcing

Introduction to Event Sourcing and Read-Model

Projections

Jeffrey T. Fritz@csharpfritz

http://csharpfritz.com

Page 2: Introduction to Event Sourcing

Now presenting…

Jeffrey T. Fritz ASP.Net Developer Evangelist for Telerik AJAX

controls Microsoft MVP, ASPInsider Tech Ed 2012 Speaker Idol Finalist, 2013 Runner-

up 15 years of web development experience CodeProject.tv + Pluralsight author (coming

soon!)

May 2013 MSDN Magazine: One ASP.Net DotNetRocks #855 Yet Another Podcast #98, #106

Page 3: Introduction to Event Sourcing

Level setting: n-tier architecture

Event Sourcing – definition, benefits, challenges

How do I get started?

How do I audit?

Rebuilding and Reporting Samples

Agenda

Page 4: Introduction to Event Sourcing

Level Setting

Database

Business Logic Layer

Presentation Layer

Data Access Layer

Page 5: Introduction to Event Sourcing

Event Sourcing: An architectural pattern which warrants that your entities do not track their internal state by means of direct serialization or O/R mapping, but by means of reading and committing events to an event store

Event: an immutable object that describes a change that has occurred to an entity.

Definition

Page 6: Introduction to Event Sourcing

Entities are not stored as a given state in time

Changes to the entities are persisted

Stored in the order changes were applied to the object

No concern for ‘prior state’ of the entity

Objectives of the Event Store

Page 7: Introduction to Event Sourcing

Account Register = Event Store

Image courtesy of Greg Young

Page 8: Introduction to Event Sourcing

Sample Events

Page 9: Introduction to Event Sourcing

Sample Events

Page 10: Introduction to Event Sourcing

Sample Events for a Cart

Page 11: Introduction to Event Sourcing

Simplified data access◦ Append-only data store◦ Easy to partition◦ Easy to replicate

Event structure allows for greater use of ‘ubiquitous language’

Reporting requirements are required to be stored separately

Benefits

Page 12: Introduction to Event Sourcing

Performance◦ Documented performance on an i7 laptop with

SSD storage: 15,000 writes / second 50,000 reads / second

◦ Aggressively cache query results Data never changes

Benefits

Page 13: Introduction to Event Sourcing

Testing◦ Given (Collection of Events)

◦ When (Action)

◦ Then (Events expected)

No duplicate storage of data ◦ Current State◦ Audit log

Benefits

Page 14: Introduction to Event Sourcing

Tivo for your entities◦ Trivial to ‘replay’ the events to a given point in

time

Offline processing

Conflict Management

Benefits

Page 15: Introduction to Event Sourcing

Not storing data in relational structure◦ Can use RDBMS as a store

Reporting is NOT immediately available

Difficult to migrate a legacy app to

Harder to sell to an organization

Challenges

Page 16: Introduction to Event Sourcing

ObjectID

ChangeDate

ChangeUser

Field Old Value

New Value

1 9/20/12 Jeff Attend 0 1

Compared to a Change History Table

ObjectID

Version

DateStamp

Event

1 5 9/20/12 RsvpChanged { Name: Jeff,Attending: true}

Page 17: Introduction to Event Sourcing

Jonathan Oliver EventStore◦ .Net based tool◦ Supports storage in: MySQL, MSSql, SQLite, Access,

Sql Azure, Amazon RDS, Oracle, Sybase, Postgres, DB2, RavenDb, MongoDb, CouchDb, and LOTS more

◦ http://github.com/joliver/EventStore

Greg Young Event Store◦ JSON based event store◦ Proprietary storage engine◦ RESTful access◦ http://geteventstore.com

Tools Available

Page 18: Introduction to Event Sourcing

Demo:Jonathan Oliver Event Store

Get and Save

Page 19: Introduction to Event Sourcing

Auditing Capabilities AuditLog is just a dump of events

Call ToString on each event

Demo – NerdDinner AuditLog

Page 20: Introduction to Event Sourcing

Data can be “re-projected” into any format

New data can be discovered by the projection that wouldn’t normally be visible in 3rd normal form

Alternate storage of data in format for the report desired

Reporting Capabilities

Page 21: Introduction to Event Sourcing

Offline re-build of reporting data

NerdDinner.Rebuild

Rebuilding Capabilities

Page 22: Introduction to Event Sourcing

Use AAA syntax◦ Arrange (collection of events)

◦ Act (action)

◦ Assert (verify output of events)

Testing Capabilities

Page 23: Introduction to Event Sourcing

http://bit.ly/FritzES -- Event Sourcing Links http://csharpfritz.com @csharpfritz on Twitter

Thanks for attending!

Resources