Posts
1150
Comments
891
Trackbacks
1
cqrs for dummies – example – when returning a value from a command makes sense

In a previous post, I talked about why I have broken from tradition and created command handlers that returned a value.  I want to give a brief example of where that makes sense.

ELT is a legitimate software development project

There are many times when I develop software that involves heavy UI usage and/or involves something like a domain in the sense of DDD.

However, there are many other times when I’m doing something else, and that is when I am developing ETL software.  ETL ( Extract Transform Load) is definitely less ‘sexy’ but is often a crucial part of many software projects overall.  You need to take data from somewhere (often from multiple somewheres), alter it, and load it somewhere else.

Most of these projects are procedural and boring.  Do step 1, then step 2, then blah blah blah, till step x.

CQRS fits well here.  You have commands and you have queries.  You read some data, then issue commands based on that data.

Here’s the thing.  In an ETL sort of situation, you want to know that your commands succeed before you go to the next step, because you need the results of those commands, one way or another.  You aren’t in an eventual consistency situation, and you aren’t in a scalability situation where you need to issue huge numbers of commands in parallel.  You simply need to know that the command you issued succeeded (and possibly get some information back).

A simple situation: you issue a command to go and get a file from an external source.  As a result of that command, the file might end up in some particular location.  Regardless, the command has to succeed before the next step occurs as the file has to have been retrieved.

Sure, you could set up an infrastructure where you send a void command that gets handled and then produces events that are published to some mechanism that records them in some read-only query result that then tells you you can move onto the next step.

The obvious question is, why in the hell would you want to do that?  Why not just let the command return that it was successful and/or with whatever data you need to move onto the next step?

It isn’t CQRS if you let commands return a value

You can argue semantics all you want.  It isn’t CQRS that involves sending commands into a domain that produces events that are then published and subscribed to in a way that allows a query to read it off of a read-only data store.  No doubt about that.  But, IMO, none of that is inherent in any and every CQRS situation. 

YMMV. 

posted on Saturday, May 14, 2011 11:36 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 1 and 6 and type the answer here: