Thoughts around REST, DDD, and CQRS: Models, Queries, and Commands

279 views
Skip to first unread message

Kevin Swiber

unread,
Sep 4, 2011, 3:32:25 PM9/4/11
to the-design-of-distr...@googlegroups.com
Kicking around ideas related to an architecture combining the best of DDD, CQRS and REST, I keep trying to organize concepts in my brain.

Warning:  This is a braindump.  Looking for feedback.

When I think about throwing REST on top of CQRS, I keep envisioning multiple models of reality.  This assumes a significantly complex Domain Model and application requirements.

Models:
1. Client Model, a representation on the client for view binding, etc.
2. Application Model, developed in terms of application state, exposed as representations of resources via REST services.
3. Reporting Model (Query), query results to the application (DTO's). 
4. Domain Model, developed in terms of business language and processes.
5. Data Model, developed for persistence.

Query sequence:
1. Client follows a GET request to a REST service.
2. REST service goes through a thin data layer to grab DTO's for constructing the resource representation requested by the client.
3. REST service returns the constructed representation to the client.
4. Client builds its own model based on the GET response and binds to the UI.

Command sequence:
1. Client submits a request to a REST service, asking to alter a resource (PUT, POST, DELETE, etc.).
2. REST service constructs a command and pushes it to the command queue.
3. REST service responds to the client with 202 Accepted.
4. A command handler processes the command through the Domain Model, which publishes events.
5. Event handlers fire.  Some event handlers will persist changes to a data store.

There are certainly many variations on this, especially for less complex scenarios.

I would love to come up with a demo, maybe starting with BDD style specs in the Gherkin syntax.  GitHub can make collaboration around this easy-peasy.

What are your thoughts?

--
Kevin Swiber
Projects: https://github.com/kevinswiber
Twitter: @kevinswiber

Bryan Hunter

unread,
Sep 6, 2011, 1:01:21 PM9/6/11
to the-design-of-distr...@googlegroups.com
Your suggestion of bringing GitHub into the mix would be very helpful to the group. Without code, it's very easy to enter the land of fog. What do you think of creating a GitHub organization for the group? https://github.com/account/organizations/new 

-Bryan

Benjamin van der Veen

unread,
Sep 6, 2011, 1:03:10 PM9/6/11
to the-design-of-distr...@googlegroups.com
On Tue, Sep 6, 2011 at 10:01 AM, Bryan Hunter <bryan....@fireflylogic.com> wrote:
Your suggestion of bringing GitHub into the mix would be very helpful to the group.

At first I read this as getting GitHub employees to post on this list, which would also be awesome. ;) 

Travis Smith

unread,
Sep 6, 2011, 1:07:41 PM9/6/11
to the-design-of-distr...@googlegroups.com
I know a couple, we could invite them :). I'll reach out. 

-Travis

Kevin Swiber

unread,
Sep 8, 2011, 12:07:31 PM9/8/11
to The Design of Distributed Applications


On Sep 6, 1:01 pm, Bryan Hunter <bryan.hun...@fireflylogic.com> wrote:
> Your suggestion of bringing GitHub into the mix would be very helpful to the
> group. Without code, it's very easy to enter the land of fog. What do you
> think of creating a GitHub organization for the group?https://github.com/account/organizations/new

Great idea. I've got an Organization set up. I'll slap together some
code to get us started.

Eugene Goncharov

unread,
Sep 19, 2011, 4:21:51 AM9/19/11
to The Design of Distributed Applications
Hi Guys,

I want to share some of our experience regarding this topic. Frankly
speaking we are using this technique in development of our new web
project.
After some investigations we've decided to use Backbone library on the
client-side in order to map client models to REST facade on the server
side.

One more interesting thing that we've decided to try is that we
actually extended the way Backbone syncs with the server and make it
so all the commands sent from the client to the server in JSON format
and the server has one entry point for all commands that de-serialize
commands and dispatch them into a command bus.

On the event handlers side - it is easy to have some push mechanism
from the server to the client which will be sending domain events to
all clients. If a client implementation supports handling of these
events - you easily can come up with some sort of real-time updates.

I hope this will be helpful.

Regards,
Eugene
Reply all
Reply to author
Forward
0 new messages