Search code examples
database-designneo4jgraph-databasesdatabase-partitioning

Multiple 'databases' within one graph database


I use GrapheneDB for hosting my neo4j database (db).

The problem

I have N clients and am looking for ways to automatically separate their content (their unique db) such that:

  • it does not overlap the data
  • the speed of operations is not harmed.

Option 1

Since I am unfamiliar with creating new neo4j servers automatically, and want to keep the things simple, my idea is to attach an unique databaseId to every node and relationship in the graph.

Then obviously I would apply queries with that restriction in mind.

Option 2

Another idea would be to create a root node and create a relationship for all nodes with the rootnode.

Questions

My questions are:

  • which option is better in terms of speed and by how much?
  • is this a feasible method, i.e. do you see advantages/disadvantages?
  • will it affect the speed when I have lots of data (N --> /inf)? My thought is that it will not since you apply the databaseId restriction (e.g. in noSQL this works perfectly fine), but I am not sure it will hold as well for a neo4j graph db.

Solution

  • As a general suggestion (since I know nothing about your use cases), I would try to use a disjoint set of node labels for each "logical DB" (LDB). That would make it easy to create and access nodes that belong to a specific LDB. And, if you only create relationships between nodes with labels that belong to the same LDB, then graph traversals will also stay within the same LDB.

    Neo4j can quickly get nodes by label, and you can also create indexes so that you can find label/property combinations efficiently.