8

I've been searching online for any information relating to using both Domain Driven Design and Graph databases such as Neo4j, I've got to say there's not a lot of information to be had!

My main queries come in with the apparent overlap between the two, i.e. both graph databases and DDD model the domain, Graph databases however only hold state, not behaviour. I'm not really sure how to mix the two... how do I mix in the behaviour? Perhaps using domain services? Creating domain entities/values for each graph node seems a ridiculous way to add behaviour.

Any ideas?

raven-king
  • 1,550
  • 2
  • 18
  • 40

2 Answers2

5

They can co-exist in a way that graph databases are commonly used on the "read" side.

What people do sometimes is they apply CQRS to a given Bounded Context and use Graph DB for projections where it makes sense.

Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
3

This depends on your bounded context and how you use the data.

data consuming bounded context:

You could use a domain service to hide technolegy details. There is a very good example in the famous dddsample. They use a RoutingService to seperate routing knowledge(evloved as routing bounded context) from cargo booking bounded context.

The implementation behind the domain service is probably even not developed using ddd. You could develop it in a graph database friendly way.

data producing bounded context:

CQRS may be a good solution to fix the gap between domain model and graph database. In this case, domain models are used to to produce calculated nodes and relationships.

Yugang Zhou
  • 7,123
  • 6
  • 32
  • 60
  • Let me just see if I understand... you propose that I could use CQRS so that I can use the graph database as the Query model and the domain model as the Command model? If this is the case I'm still unsure about the interaction between domain (Command) and graph (Query)... would the domain model still update the traditional data store (most likely relation DB) then the graph be notified so that it could reflect the changes. This doesn't really bridge the gap between behaviour (provided by domain) and state (provided by graph). Have I misunderstood? – raven-king Dec 19 '13 at 09:07
  • 1
    Domain state can be stored in either pure EventSourcing solution, or in key/value store in serialized form. Events are then denormalized into RDBMS, graph database, or whatever, depending on your query needs. – Rickard Öberg Dec 19 '13 at 14:29