Property graph (Neo4j) design: Single node with multiple relations or new nodes for each event occurence?

193 views Asked by At

Let us say I've two Leagues L1 and L2. Each league can have multiple rounds like Playoffs, Quarterfinals, Semifinals and Finals. Moreover, I also need to represent the happens_after fact like Quarterfinals happens after Playoffs, Semifinals happens after the Quarterfinals and Finals happens after the Semifinals.

Questions

Should my graph have one node for each of these rounds and each League should link to these rounds? This way we are just creating new relationships (e.g. both L1 and L2 will have a relationship to Playoffs) but there is only one Playoff node. However, this limits the happens_after relationship because some leagues can have more rounds (for e.g. Round 2 can come before Quarterfinals). Is there a better way to represent this?

Use-cases

  1. Need to be able to find all the rounds of a given league.
  2. Need to be able to find the order of all the rounds of a given league and the dates each of these happened.

EDIT

enter image description here

1

There are 1 answers

4
Stefan Armbruster On

In general everything that has an identify on its own should become a node. Relationships tie the "things" together.

Not sure if I fully understand your domain. L1, L2 and each round would be nodes. The relationship league -> round indicates that a given league takes part in the round.

The temporal order within the rounds can be modeled by having BEFORE and/or AFTER relationships among them. This way you build a linked (or a double linked) list of rounds. Another way to express temporal order would be to store a indexed timestamp property for the round. If you're just interested in before or after and not on absolute time, the first approach (linked list) seems to fit better.