Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j, Which is better: multiple relationships or one with a property?

Tags:

neo4j

I'm new to neo4j, and I'm building a social network. For the sake of this question, my graph consists of user and event nodes with relationship(s) between them.

A user may be invited, join, attend or host an event, and each is a subset of the one before it.

Is there any benefit to / should I create multiple relationships for each status/state, or one relationship with a property to store the current state?

like image 758
user693308 Avatar asked Oct 06 '22 16:10

user693308


2 Answers

Graph-type queries are more easily/efficiently done on relationship types than properties, from what I understand.

How about one relationship, but a different relationship type?

You can query on several types of relationships with pipes using Cypher (in case you have other relationships to the event that you don't want to pick up in queries).

Update--adding console example: http://console.neo4j.org/?id=woe684

Alternatively, you can just leave the old relationships there and not have to build the slightly more complicated queries, but that feels a bit wasteful for this use case.

like image 122
Eve Freeman Avatar answered Oct 10 '22 03:10

Eve Freeman


When possible, choosing different relationship types over a single type qualified by properties can have a significant positive performance impact when querying the graph. The former approach is aways at least 2x faster than the latter. When data is in high-level cache and the graph is queried using native Java API, the first approach is more than 8x faster for single-hop traversals.

Source: http://graphaware.com/neo4j/2013/10/24/neo4j-qualifying-relationships.html

like image 22
delsanic Avatar answered Oct 10 '22 03:10

delsanic