Archive for the ‘Event Sourcing’ category

When should you use CQRS or event sourcing?

February 28th, 2013

I am currently in the process of helping migrate our current legacy application to an event sourced system, also known as a CQRS (Command Query Responsibility Segregation) system.  We have had some pitfalls for sure and I wanted to outline some of that in this post.  We went with the LOKAD system which can be found here: Lokad Project.  It has hooks into the Microsoft Azure cloud solution so it was a great starter for us to get rolling with that.

The system actually ran fine for quite a while just getting data in and out, things were working perfectly until we decided to throw a lot of commands at the server and see how that processes that.  Rinat Abdullin, the creator of LOKAD outlines that here: Lokad Event Store is slow, we were using the azure blob storage and all that serialization/deserialization causes some serious performance issues when you multiply that by n number of times.  We have moved to the Event Store written by Greg Young found here: Event Store.  This speeds up the writes of the LOKAD system when it comes to the events but still didn’t solve the problem of our read models and how this system likes to make these projections.

If you have been following some of my blog posts in the past, you would know that I have done some research with couchdb, well a co-worker at my work place has been doing a lot of research into Couchbase which leverages couchdb with memcache.  I already liked it cause they used couchdb and I knew how performant that was, what I didn’t know was that it caches a lot of the calls and data, so its in memory and extremely performant.  Our plan is to replace our current readmodels being stored in the azure blobs, which can get quite large, so the serialization/deserialization in some situations can bring performance down to a crawl, to be stored in couchbase.

Anyway, back to my original question, When should you use CQRS or Event Sourcing?  My advice would be to analyze your companies requirements and ask yourself if a system like this would truly give you a reward worth the investment?  My personal opinion is for most business applications it is not needed or necessary to track the intentions or actions on data.  There are some business use cases that I could see it being good for, take banking for instance, its critical to know how the money got from point A to B, or accounting, again mission critical.  Greg Young says he does not like Case Studies, that they are too gimmicky, read his post here: Greg Young Case Studies So I still cannot find a really good case study but I did come across this guys blog post which pretty much sums my overall views on the pattern: A Year in review with cqrs he pretty much came to the conclusion that he doesn’t use the pattern for its intent and a key/value store would have done the job just as well.

There are people out there that think most all applications should be written with this pattern, all I am saying is look at what your needs are and make a judgment call there. I am potentially looking at making a mobile version of a website I worked on with a friend, there is no way I would implement an event sourced system in this situation, it won’t make sense and my client is not going to pay for it, you have to factor in the time it takes to model out the domains and figure out what actions are to be performed on the data.

If you are currently implementing a system like this, I welcome your comments, feel free to leave em, you won’t hurt my feelings. I too am trying to see the real value in a system like this.