Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to partition a single Neo4j database?

Tags:

neo4j

Can one Neo4j database be divided up so that there are multiple starting points in one database so that all queries can be isolated, instead of having multiple databases?

I have thought about this and I think it can work up to a point, but once things like labels are used then the idea will not work, as a label query will always span the whole database.

Anyway I would like to know if anyone has successfully done this and how they did it.

like image 664
yazz.com Avatar asked Mar 09 '14 06:03

yazz.com


People also ask

Can Neo4j be distributed?

With today's launch of Neo4j 4.0, the company has taken the first step in creating a distributed graph database that spans multiple physical systems. Neo4j is not yet a fully distributed graph database, even with 4.0.

Can you Shard Neo4j?

Neo4j Fabric is Neo4j's solution to graph sharding by allowing users to break a larger graph down into individual, smaller graphs and store them in separate databases.

What kind of databases can Neo4j fabric handle?

Fabric allows you to retrieve data from all your databases with a single Cypher query. As the databases db0 , db1 , db2 in this tutorial are part of the same Neo4j DBMS, you can also access them directly, using their database names.

What is the default database in Neo4j instance?

The default database is named neo4j (can be changed) and is where we can store and query data in a graph and integrate with other applications and tools.


1 Answers

What you are describing sounds like multitenancy. Neo4j 2.0.1 does not at this time support multitenancy as a feature. There are various methods and strategies for implementing a multitenant architecture within your Neo4j database instance.

You can partition sets of your property graph by label. Since nodes can have multiple labels, you can label one partition with a unique identifying label for that partition.

Please refer to documentation on labels here: http://docs.neo4j.org/chunked/milestone/graphdb-neo4j-labels.html

Things to note with this strategy are to ensure that all your Cypher calls contain the partition identifier for the label, to ensure that the two partitions are isolated from one another within the graph. It's important to ensure that relationships from one partition do not span into another partition.

For example, partition 1 could be the label Partition1. Assuming your application context is operating on Partition1:

MERGE (user:User:Partition1 { name: 'Peter' })
RETURN user

Assuming your application context is operating on Partition2:

MERGE (user:User:Partition2 { name: 'Peter' })
RETURN user

When executing these two queries, two separate Peters are created for Partition1 and Partition2.

You'll just need to ensure that the partition label your application is operating on appends its label to each one of your queries. While this is tedious, it is the suggested way to go about multitenancy at this time.

like image 131
Kenny Bastani Avatar answered Sep 18 '22 07:09

Kenny Bastani