Greg recently posted on the benefits of using event sourcing instead of traditional state-based persistence mechanisms. It's a great article and definitely worth reading multiple times. But there was one paragraph in particular that caught my attention that gave me one of those great ah-ha moments.
One of those benefits is that we can avoid having to use a 2pc [two-phase commit] transaction between the data model and the message queue (if we are using one)… the reason for this is that the event storage itself is also a queue, we could be trailing the event storage to place the items on the queue (or directly use the event storage as a queue).
The reason this is so important is because it gives tremendous insight into the actual implementation of Greg's architecture. In an article from a few days ago, he said the following:
Firstly when one uses Event Sourcing with CQRS one can avoid the need for 2pc between the data store and the message queue that you are publishing messages to. This is because the Event Store can be used as both an event store and a queue. Conceptually the Event Store is an infinitely appending file. One can just have a read location that gets updated (chasing the end of the file) and presto you have a queue as well. A side benefit from this is that you also end up with only one disk write for both your storage and your durable queue, this may not initially seem like a big win but when you are trying to build performant systems this can help a lot!
I should mention that I understand the event store and its benefits, but the thing that I hadn't considered is that we would publish the committed events in a separate transaction from the commit to the event store.
What's really cool about this is that we can have another process watching the event store which can be publishing committed transactions to the bus so that our read model, or other services, can become aware of those updates.
There are a few additional insights that I'm digging out of the above paragraphs in light of what Greg has said in some of his early material. I'll be publishing more soon.