Partial Event Sourcing (ES + CRUD)

717 views
Skip to first unread message

Ryan Litvak

unread,
May 15, 2013, 10:36:58 AM5/15/13
to ddd...@googlegroups.com
Hi, long time follower, first time poster...
 
I am working on understanding the nuances of event sourcing.  For the project I am working on I see a lot of benefit in moving to this approach.
 
What I am having trouble with is not event sourcing everything.  I get that ES is overkill for CRUD but there are quite a few objects in the database that themselves contain little to no behavior beyond CRUD but they are used as references to other objects which contain a lot of behavior.
 
For instance, this is a manufacturing environment:
 
Product moves down the line. 
  • It arrives at stations
  • It is operated on (parts being assembled, tests being run, etc...)
  • it completes operations (successfully or not)
  • It moves to next station
  • It is packed in containers
  • etc...
However there many objects that are there to describe materials used, receipe for product (all parts needed to build product).
 
In order to have a complete picture at any given point in time wouldn't I need to event source the basic CRUD operations on those objects?  Or do you denormalize their state into the event?
 
Thanks again,
 
Ryan

Vytautas Mackonis

unread,
May 15, 2013, 10:51:55 AM5/15/13
to ddd...@googlegroups.com
Hi,
There is a great talk made by Udi regarding this, although it is in somewhat broader context than ES vs no ES debate:




 
Ryan

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

@neilbarnwell

unread,
May 16, 2013, 4:39:39 AM5/16/13
to ddd...@googlegroups.com
This is one of those situations where choosing to use ES changes the landscape a bit. Personally I don't think ES can work very easily if at all unless you're applying some level of CQRS. Greg's EventStore actually does appear to give you the ability to use it as the only data store but that's a special case because it's been designed from the ground up to be a good ES storage system.

For me, I only store aggregates (i.e. my domain) in my event store. All those other things (e.g. names of countries) come from somewhere else. Perhaps from a sql database, or a bunch of text files, hard-coded, even.

However I'd suspect that more of the things you're talking about are actually domain objects anyway. Products almost certainly are, and also the "recipe" (which I'd call "Bill of Materials"?). Anything with rules around it that's a core concept in a domain that crops up regularly in talks with domain experts is *likely* to be an entity in the domain. So in summary - those things that really are simple things or lists of text, put them wherever you like. However you'll probably find there are more "real" entities than you thing, which you should model in your domain and persist in your event store as such.

The real question is - if you model something as an entity and your *commands* persist it in an event store, how do you *query* for them in different, useful ways? CQRS is the answer, and essentially you write projection code that takes events generated by your entities and uses them to build an additional Read Model that's whatever you need it to be. Maybe more than one... I personally am taking events emitted by my domain and sending them through a publisher. There are currently several subscribers to those messages:
  • SQL read store updater.
  • Neo4j graphdb read store updater (planned).
  • Mobile device database updater.
  • SignalR-based desktop client updater.
If my app needs to perform simple queries over things like Products (that are stored as event streams in a RavenDB database using my Regalo library and are therefore tricky to query easily) then I'll make sure to build a Products table in the SQL read store that's maintained by the projection app. In things like MVC controllers then I use the Simplest Thing That Could Possibly work - I open a SqlConnection and use Dapper to grab the data and hydrate some ViewModel objects that are rendered in Razor and sent to the browser.

That's quite a lot of typing. I hope I haven't missed the point of the question...  :S Still, hope it's useful anyway.

Ryan Litvak

unread,
May 16, 2013, 8:16:41 AM5/16/13
to ddd...@googlegroups.com
Well I had a long response written and my machine locked up so I will just summarize now.
 
Thank you Vytautas for the link to Udi's talk. It was very helpful.
 
Neil I am moving the code base to CQRS but I wanted to incorporate ES to prevent data loss from compressing to current state.
 
However, what I am realizing is that I still have a lot of work to do getting my bounded contexts right.  Before I even worry about ES I really need to go back to the drawing board and get the BCs right.  I still require a lot of request/response communication between BCs and that is a function of just trying to group the nouns from the large monolithic domain I inherited and call those bounded contexts. 
 
I am sure I will have more questions in the future.  Thank you for the responses, they have been very helpful.
 
Regards,
 
Ryan
Reply all
Reply to author
Forward
0 new messages