5
votes

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?

2
i think for the sake of simple programming code you should use one relationship type (e.g. "EVENT") and its property (e.g. "status:attend"). but if you really must max the speed please use the relationship types as suggested belowulkas

2 Answers

2
votes

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.

2
votes

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