Introduction to Event Sourcing
-
Upload
jeffrey-t-fritz -
Category
Technology
-
view
179 -
download
2
description
Transcript of Introduction to Event Sourcing
![Page 1: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/1.jpg)
Introduction to Event Sourcing and Read-Model
Projections
Jeffrey T. Fritz@csharpfritz
http://csharpfritz.com
![Page 2: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/4.jpg)
Level Setting
Database
Business Logic Layer
Presentation Layer
Data Access Layer
![Page 5: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/7.jpg)
Account Register = Event Store
Image courtesy of Greg Young
![Page 8: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/8.jpg)
Sample Events
![Page 9: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/9.jpg)
Sample Events
![Page 10: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/10.jpg)
Sample Events for a Cart
![Page 11: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/12.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/13.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/14.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/15.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/16.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/17.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/18.jpg)
Demo:Jonathan Oliver Event Store
Get and Save
![Page 19: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/19.jpg)
Auditing Capabilities AuditLog is just a dump of events
Call ToString on each event
Demo – NerdDinner AuditLog
![Page 20: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/20.jpg)
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](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/21.jpg)
Offline re-build of reporting data
NerdDinner.Rebuild
Rebuilding Capabilities
![Page 22: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/22.jpg)
Use AAA syntax◦ Arrange (collection of events)
◦ Act (action)
◦ Assert (verify output of events)
Testing Capabilities
![Page 23: Introduction to Event Sourcing](https://reader035.fdocuments.us/reader035/viewer/2022062304/5593381f1a28aba90f8b45c0/html5/thumbnails/23.jpg)
http://bit.ly/FritzES -- Event Sourcing Links http://csharpfritz.com @csharpfritz on Twitter
Thanks for attending!
Resources