CAP Theorem, CQRS and Eventually Consistent

First, if you haven’t heard of Eric Brewer’s CAP theorem, it basically states that you can must choose two of three:

  • Consistency
  • Availability
  • Partition Tolerance

CQRS doesn’t solve CAP issues, however it allows you to decide independently what is important on both read and write side.

For example, you could assume a systems would be ACID (Atomic, Consistent, Isolated, Durable) compliant on the write/domain site and BASE (Basic Availability, Soft-State, Eventually Consistent) on the read side.

Eventual consistency is something that requires a change of mindset.  Because of our heavy use in ACID compliant databases, thinking about possibly having stale data blows our mind.

There are two important points about I want to make about eventually consistent data.

  • The data isn’t wrong.  It’s old.  There is a big difference here.  The data you may be consuming may not be up-to-date, however it was correct at one point in time.
  • In the real world, we use stale data all the time.

A good example, from Greg Young, was if you read the newspaper/website and notice some statistics on the unemployment rate, this is obviously stale data.  If those stats were a a week old, would this matter?  How much of a difference would a week make to unemployment rate?  Probably not much. However, there are scenarios where you want to be much closer to actual, and in these cases define an SLA.

The point is, in many situations, eventually consistent data is acceptable.

Service Bus for Windows Server

Move over MSMQ, Service Bus for Windows Server was recently released.  Apparently it has been for awhile now (Oct 2012 release).  I’m just late to the party I guess.

Service Bus 1.0 was designed to allow for enterprise messaging capabilities in a Windows Server-based environment.  It enables you to build, test, and run loosely-coupled, message-driven applications in self-managed environments and on developer computers.  The two primary features are Service Bus Queues and Service Bus Topics and Subscriptions.

  • Service Bus Queues offer reliable message storage and retrieval with a choice of protocols and APIs. Use Service Bus queue in your application to provide load leveling by having the message receiver processing messages at its own pace or to provide load balancing by having multiple, competing receivers accepting messages from the same queue.

For more information on Service Bus queues refer to How to Use Service Bus Queues.

  • Service Bus Topics and Subscriptions offer (in addition to all of the queue’s) rich publish-subscribe capabilities allowing multiple, concurrent subscribers to independently retrieve filtered or unfiltered views of the published message stream.

If you are interested in or use messaging technology within your applications, this is some pretty exciting news.  Service Bus for Windows Server provides the same capabilities (Message Queues, Pub/Sub) as the Windows Azure Service Bus.  Best of all, it’s free.

It’s available for download now.  Also, check out the MSDN documentation.

Event Sourcing: Eric Evans Interviews Greg Young

I follow Eric Evans (@ericevans0) and Greg Young (@gregyoung) on twitter.  I really respect their opinion and knowledge.

Eric tweeted about an interview he did with Greg over 5 years ago about Event Sourcing.  It’s great to hear Greg describe how Event Sourcing fits with DDD concepts.  This is video is one of the first Event Sourcing + DDD talks that I’m aware of.   I highly recommend checking  it out.

If you are new to Event Sourcing, here is a snippet from Martin Fowler article.

Capture all changes to an application state as a sequence of events.

We can query an application’s state to find out the current state of the world, and this answers many questions. However there are times when we don’t just want to see where we are, we also want to know how we got there.

Event Sourcing ensures that all changes to application state are stored as a sequence of events. Not just can we query these events, we can also use the event log to reconstruct past states, and as a foundation to automatically adjust the state to cope with retroactive changes.