Event Sourcing

     Raza Z Sayed

Lead Developer @ Idyllic Software



Problem 1: CRUD does not work always...


  • 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



Event Stores/Event Sourcing Libraries

For Ruby On Rails developers (Theres a gem for that !):


For .Net, Javascript developers

For Java developers


Thank You !

We are hiring awesome Ruby, Node, iOS and Android developers !

Get in touch at : commons@idyllic-software.com