Event Sourcing
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624713/github_icon.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624725/twitter_logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1625693/logo-2x.png)
Problem 1: CRUD does not work always...
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1623866/Screen_Shot_2015-08-06_at_7.36.20_pm.png)
Solution
- Dont save the current state
- Save the "events" that lead to the current state
Problem 2: Monitoring Changes in a real-time app
- In a music application for example the push notification service needs to know when an album has received a comment to notify the artist
- Involves traditional approaches like 'polling'.
Solution: Event Sourcing
- Dont store current state !
- Store every data transition as an 'event' that occured separately. (solves the CRUD problem by being able to replay the events to determine how current state was reached)
- Notify interested parties of events by publish-subscribe mechanism using for example a message-bus. (solves the problem with monitoring for changes in a real-time application)
Event Sourcing is 'not' a new idea !
Examples of event sourcing in everyday life...
- Bank Account Statement
- Patient Medical Records
- etc..
How to 'efficiently' query the events ?
- CQRS (Command and Query Responsibility Segregation). This makes event sourcing practical !
- 'Projections' is a technique used to implement CQRS and it works by converting raw json serialized event data into a form suitable for querying by storing it in an 'appropriate form'.
- Projections provide the beneficial side effect of 'Polyglot Data' !
Simple Example of Event Sourcing Architecture
CreateAlbum (Command)
CreateComment (Command)
Event Store e.g. EventStore
CreatedAlbum Event
{"name": "The Beatles"}
CreatedComment Event
{"text": "Its amazing !"}
Message Bus e.g. RabbitMQ
Albums microservice
Comments microservice
Store event and publish to a message bus using AMQP for example
Subscribe to Album events
Subscribe to Comment events
Albums Database
Comments Database
Using Projection
Using Projection
Notify Artist
Query
Query
Event Stores/Event Sourcing Libraries
For Ruby On Rails developers (Theres a gem for that !):
- rails_event_store (Ruby port of Greg Youngs EventStore)
- event_sourced_record (Event Sourcing library)
- rails-disco (Event Sourcing library)
- etc ! (http://fhwang.net/g/Event-Sourcing-Libraries-in-Ruby-A-Guide)
For .Net, Javascript developers
- EventStore (https://geteventstore.com/)
For Java developers
- EventStore.JVM (https://github.com/EventStore/EventStore.JVM)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624695/java-logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624698/Microsoft_.NET_Framework_v4.5_logo.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624700/nodejs_120-b09a243cafd8e949.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/360956/images/1624702/Ruby_on_Rails.svg.png)
Questions
Thank You !
We are hiring awesome Ruby, Node, iOS and Android developers !
Get in touch at : commons@idyllic-software.com