Archive for the ‘Distributed Programming’ 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.

Windows Azure ServiceBus Demo

May 18th, 2012

Recently I was put to task with doing some research on the Windows Azure ServiceBus for an upcoming project at my workplace and I was rather impressed with what I found. I have put a repo out on github for anybody that is interested. I began down the road of something like what is seen on this site: https://www.windowsazure.com/en-us/develop/net/how-to-guides/service-bus-queues/ The problem with following those directions on the link I just sent is that it defaults to some custom port that is not 80 and that wouldn’t work in my situation due to the fact that our app would be out in the public and I didn’t want to burden my clients with having to open up that port on their firewalls, so I went with a REST-based implementation.

The demo has two wpf windows in which you will need to make a couple of changes to work with your azure account, I have a snippet below that shows the spots that need to be changed.

 static string serviceNamespace = "<YourNamespace>";
 static string baseAddress;
 static string token;
 const string issuer = "owner";
 const string key = "<YourKey>";
 const string sbHostName = "servicebus.windows.net";
 const string acsHostName = "accesscontrol.windows.net";

Here is the link to the GitHub repo: https://github.com/eddie1459/WindowsAzure

Enjoy.