Corey Coogan

.Net, C#, ASP.NET MVC, Architecture and Design

Command Query Responsibility Separation (CQRS)

Posted by coreycoogan on November 18, 2009

CQRS is a relatively new way of architecting systems that is the topic of much discussion on the DDD lists.  The biggest proponents (creators?), Udi Dahan and Greg Young, are constantly answering question, giving suggestions and presenting the architecture at conferences around the world.  It’s fascinating and I really like what I’ve read and watched, but I’ve always had trouble grasping the ideas as a whole, especially Event Sourcing, without something concrete to look at.

UPDATE: As pointed out by Mark Nijhof in the comments, Greg and Udi have slightly different philosophies.  We’re talking about Greg’s flavor here.

The gist of CQRS is that you access your domain model for updating via commands and a separate service from the reads (queries) and reporting.  Reading from your database happens without going through the domain layer and can be performed against a denormalized database by passing simple and complete DTO’s to the UI.  The updates to the domain eventually update the read-only database when the published event messages get picked up and acted upon.

Thanks to Mark Nijhof, I have something more in depth that I can read and also a code base I can examine.  Anyone who is interested in this architecture should read this post now.  It is pretty well written and really helps solidify the essence of what CQRS looks like the problem it is trying to solve.

2 Responses to “Command Query Responsibility Separation (CQRS)”

  1. Hi Corey,

    I am happy to see you enjoyed my post, I am also going to give a talk about the example code for E-VAN tomorrow. And I have a few more indept posts in mind. I am looking forward to your input.

    One thing to note is that Greg and Udi have a different opinion with respect to the Event Sourcing bit. Where Greg is in favour Udi likes to not store the events but the actual domair, like it is comonly done right now. I think depending on your environment you should make a choice. If I can I will favour Event Sourcing

    • coreycoogan said

      Thanks for the excellent service Mark. I read almost every post on the DDD list each day and lost track of the subtleties between Greg and Udi. I appreciate you clearing that up and I’ll make an update to your comment.

      Keep up the contribution. I’m looking forward to more great stuff!

      Corey

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>