introduction to event sourcing
DESCRIPTION
Presentation slides from sessions discussing Event Source data storage and read-model projections. Source code from demos at: https://bitbucket.org/csharpfritz/nerddinner-cqrsTRANSCRIPT
Introduction to Event Sourcing and Read-Model
Projections
Jeffrey T. Fritz@csharpfritz
http://csharpfritz.com
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
Level setting: n-tier architecture
Event Sourcing – definition, benefits, challenges
How do I get started?
How do I audit?
Rebuilding and Reporting Samples
Agenda
Level Setting
Database
Business Logic Layer
Presentation Layer
Data Access Layer
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
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
Account Register = Event Store
Image courtesy of Greg Young
Sample Events
Sample Events
Sample Events for a Cart
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
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
Testing◦ Given (Collection of Events)
◦ When (Action)
◦ Then (Events expected)
No duplicate storage of data ◦ Current State◦ Audit log
Benefits
Tivo for your entities◦ Trivial to ‘replay’ the events to a given point in
time
Offline processing
Conflict Management
Benefits
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
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}
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
Demo:Jonathan Oliver Event Store
Get and Save
Auditing Capabilities AuditLog is just a dump of events
Call ToString on each event
Demo – NerdDinner AuditLog
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
Offline re-build of reporting data
NerdDinner.Rebuild
Rebuilding Capabilities
Use AAA syntax◦ Arrange (collection of events)
◦ Act (action)
◦ Assert (verify output of events)
Testing Capabilities
http://bit.ly/FritzES -- Event Sourcing Links http://csharpfritz.com @csharpfritz on Twitter
Thanks for attending!
Resources