Search code examples
neo4jarchitecturereplicationnosql

Using neo4j Replication as part of the architecture


I am working on a system which has a number of bounded contexts. The one context acts as master data for the others. It holds information such as Users, Organisation, Branches etc.

I am playing with the idea of having a master record neo4j instance with separate neo4j instances for each of the other subsystems.

Would it be possible/advisable to use neo4j replication to replicate the master record information into the other sub systems, then add additional nodes and relationships to the sub system data as required?

The intention here is to prevent the master record data from being bogged down by the data from the other sub systems. The one sub system in particular has a very dense graph and I am concerned that it would start to cause performance problems.

The neo4j replication system appears to be mainly for HA so I am not sure that using it as an architectural tool would be advisable?


Solution

  • You can't write to Neo4j slaves without them synching back to the master.

    I would probably take the individual databases and sync (manually) from the master to the slaves (e.g. with a tx commit handler or a change-feed).

    Then you can enhance your dependent bounded contexts with the individual specific information.

    You can also use an event-sourced architecture to distribute the inputs or you just replicate your write/update queries to all databases (e.g. with a load balancer).

    As long as you stay on the domain level, it should work fine (as you only match on labels and properties of your domain, not neo4j node-ids which might be different for the different machines).

    The only write queries that might fail are deletes where you try to delete nodes from the master context, but can't at the sub-contexts because they are also connected to other information in the subcontexts.

    So probably you have to use more aggressive delete queries, which make sure that all relationships of a node are deleted before you delete the node.