Constraint Validation in Neo4j

Warm Greetings to All!

I am trying to create two different graphs in Neo4j belonging to 2 different domains, say, one for a Retail Store and other for a Bank.

There are many entities which are common across two domains like Customer etc but i would like to have different Nodes created for these common entities for each domain so as to have a separate set of nodes/relationships which can be easily queried later,independently.

However, since Neo4j doesn't provide any container/workspace(unlike Grakn or other Graph dbs ) to keep different domain graphs separated from each other in a single Neo4j instance, i am using multiple labels to differentiate the Nodes of two domains.

For instance, Cypher Syntax for Customer Node of Retail Store is -

      Create (:Customer :RetailStore :Tree {id: 'Customer'})  

and, Cypher Syntax for Customer of Bank is -

      Create (:Customer :Bank :Tree {id: 'Customer'})  

However, after creating one of the graph in Neo4j i am unable to create the other graph as Neo4j throws error
"Neo.ClientError.Schema.ConstraintValidationFailed: Node(324) already exists with label Tree and property id = 'Customer'

i need 'Tree' label so as to utilize Graph Traversal API while querying the domain graphs.

I also observed that if 'Tree' label is removed then i am able to create the two graphs in Neo4j. In fact, after removing 'Tree' i am able to create the same Node 'n' number of times without getting Constraint Validation error. from Neo4j. Please try below syntax, say for 10 times, we won't get any error.

Create (:Customer :RetailStore {id: 'Customer'})

Can you please throw some light on what is special about 'Tree' & 'id', and why Neo4j doesn't throw Constraint Validation error when we don't use 'Tree' as label and try to create same node 'n' number of times(as we expect, since a node with that name & property already exists). Thanks.

You have made a UNIQUE CONSTRAINT on :Tree(id), and you are trying to create two :Tree nodes with the same id.

You can see your constraints by running :schema in the browser.

In Neo4j 4.0 you can opt to keep workspaces separated in different databases (requires Enterprise license).

Thanks @Thomas_Silkjaer for sharing the insights.