Mark Needham

Thoughts on Software Development

Book Club: Unshackle your domain (Greg Young)

with 9 comments

In this week’s book club we continued with the idea of discussing videos, this week’s selection being Greg Young’s ‘Unshackle your Domain‘ presentation from QCon San Francisco in November 2008. He also did a version of this talk in the February European Alt.NET meeting.

In this presentation Greg talks about Command Query Separation at the architecture level and explicit state transitions amongst other things.

Jonathan Oliver has created a useful resource page of the material that’s been written about some of these ideas as well.

These are some of my thoughts from our discussion:

  • I think the idea of eventual consistency is quite interesting and I can see how taking this approach instead of trying to create the impression that everything the user does is in real time we can make life much easier for ourselves.

    I’m not sure how this type of idea works when users have the expectation that when they change information on a page that it is updated straight away though.

    For example on a form I might decide to change my address and I would expect that if I reload the page with my address on that it would now display my new address instead of the old one. If that address was eventually consistent after 5 minutes for example the user might become quite confused and send in another update to try and change their address again.

    Liz pointed out that with bank transactions it is often explicitly described to users that money transfers are ‘pending’ so perhaps the expectation that things aren’t done in real time has already been set in some domains.

    Werner Vogels has a nice article about eventual consistency in distributed systems in which he references a paper by Seth Gilbert and Nancy Lynch which talks about the idea that “of three properties of shared-data systems; data consistency, system availability and tolerance to network partition one can only achieve two at any given time.”

  • Dave pointed out that the idea of ‘POST redirect GET‘ often used when processing web form submissions seems to adhere quite nicely to the idea of Command Query Separation as described in the video.

    I find it quite interesting that CQS at the method level in our code is usually quite closely adhered too but so often we’ll just bolt on getters onto domain objects so that we can access some data to display on the view.

    The idea of not doing this and having a write only domain seems very interesting and seemed to make sense in the system that Greg described.

    It would be interesting to know whether one would follow such an extreme approach at the architecture level if there weren’t such high performance requirements or the need to have all the operations performed on the system available for an audit.

  • Greg’s idea of state transitions sounds quite similar although perhaps not exactly the same as Eric Evans’ ‘domain events’ which he discussed in last week’s book club.

    It would be interesting to see what the code to process form submissions by the user would look like with this approach.

    As Silvio pointed out, the complexity of this code would probably be much higher than in a more typical approach where we might just build our domain objects straight from the data the user entered.

    Using Greg’s approach we would need to work out which state transitions had actually happened based on the user input which would presumably involve keeping a copy of the previous state of the domain objects in order to work out what had changed.

    I like the idea of making concepts more explicit though and the idea of keeping all state transitions is something that is built into databases by way of their log by default so it’s not a completely new concept.

    Pat Helland has a cool post titled ‘Accountants don’t use erasers‘ where he describes it in more detail.

Written by Mark Needham

August 29th, 2009 at 9:54 am

Posted in Book Club

Tagged with ,

  • Pingback: Twitted by planettw

  • http://derickbailey.lostechies.com Derick Bailey

    Mark,

    Just wanted to say that I’ve really enjoyed your book club posts. You’ve provided just enough detail to peak my interest and get me thinking, and provided the links to the resources to let me research these items further.

    Thanks for the great series of posts and keep them up!

    -derick.

  • http://jonathan-oliver.blogspot.com Jonathan Oliver

    Mark,

    Perhaps I can answer a few of your questions:

    Regarding the expectation for global consistency, typically the approach that Liz offered is the best one–simply show the change as “Pending”. You can adjust your SLAs so as to ensure near real-time consistency of the most critical elements of the system.

    CQS [Young] can easily work for small systems. Just remember that the justification for doing DDD (and DDDD) versus other approaches, such as transaction scripts or anemic domain models is embodied in the complexity of the domain itself. The ability to build massively scalable systems is some respects is almost a byproduct of following the principles outlined in CQS [Young].

    Martin Fowler has also written about domain events. When I watched Eric Evans presentation on what he had learned since the book, he was referring directly to Greg’s implementation. Eric interviewed Greg nearly 2 years ago at QCon in 2007 regarding domain events and state transitions and Eric was very intrigued. I think Greg proved to Eric that it does work.

    One thing to be aware of is there is some discussion among those that are using and investigating “Command Query Separation” at the architectural level about the name of the pattern because of the confusion with Bertrand Meyer’s version of CQS for individual objects. Greg is currently exploring other names. I’ve got my vote in for ”Command Query Distribution”; we’ll see how that turns out. You may want to refer to it as CQS [Young] for the time being.

    Keep the great blog posts coming.

  • http://jonathan-oliver.blogspot.com Jonathan Oliver

    “Your comment is awaiting moderation”? You mean to say that my comment is not immediately available for display on the website? I thought the world was 100% consistent at all times!

    It’s all about managing user expectations. As long as they can see that something is happening, waiting 3 seconds is okay. Actually, Udi Dahan talked about using the browser, Javascript, and server-produced JSON files to offload the loading the display of new content to the browser rather than doing all of the work server side.

  • http://www.markhneedham.com Mark Needham

    Hi Jonathan,

    I have watched the interview Eric did with Greg from QCon 2007 but I didn’t realise the idea of domain events had actually come from there. That’s cool!

    Greg was meant to do his talk at QCon London earlier in the year but I think he injured his knee the week before so he wasn’t able to come – would have liked to see that presentation live.

    I saw Greg’s recent post about CQS [Young] where he described CQS at the architecture level being about separating commands/queries at the message level rather than method level which I think is quite a nice description.

    Thanks for clearing some of that up & for your post where you’ve gathered all the resources. I’ve been going through those, still not finished.

    Cheers,Mark

  • http://www.markhneedham.com Mark Needham

    Haha for all of one minute :-D Although now you’ve posted something I think it’ll become 100% consistent!

    Ah I don’t think I’ve seen that from Udi Dahan, is it a presentation/blog?

  • http://jonathan-oliver.blogspot.com Jonathan Oliver

    There are two recordings that I have heard where Udi talks about leveraging the browser to scale rather than placing the load on the database.

    Here is the first. You have to listen to a few minutes to get the context and background, but it’s well worth it–try around minute 42 in the recording:
    http://www.dotnetrocks.com/default.aspx?showNum=367

    The other one is here. He talks about how eBay and Amazon can acheive high levels of scalability, among other things: http://elegantcode.com/2009/06/05/recording-of-udi-dahan-on-soa-e-van-01-june-2009/

  • Pingback: Accountants Don’t Use Erasers

  • Pingback: My Software Development journey: Year 3-4 at Mark Needham