Best practice: How to specify a vertex's domain 'type' in a graph database

121 views Asked by At

When building a graph, it is usually necessary to specify the 'type' of vertices. Conceptually I see this could be done by applying a vertex label or property to each vertex (ie Bob, Label: Man), or alternatively by linking a vertex to another 'type' vertex (ie. Bob --IS A--> Man).

To find a list of all vertices of type 'Man' I can write gremlin queries that work for both of these approaches. But what is best practice?

1

There are 1 answers

0
jbmusso On

Best practice: keep your data model simple and make sure it is compatible with efficient indexing by the underlying graph database. There is no one size fits all solution at the TinkerPop level.

It really depends on your data model as well as the indexing capabilities of the underlying database, not to mention the way the data is actually serialized on disk. Ultimately, it all boils down to the way you expect to query your graph and the kind of performance you wish to have.

This being said, people typically use vertex labels, sometimes used in conjunction with a type property of some kind. Graph implementers should be able to provide efficient indexes for answering such query. It should also give a simpler graph model, which is an important thing to consider.

Depending on the size of your graph, you could get performance issues when modeling types with vertices since a man type vertex could quickly become a supernode.