Graph or relational databases

From Endeavour Knowledge Base

A question arises as to whether the Discovery Data Service should use relational, property graph, document, or key value based database management systems  in its main patient record data stores.

This article considers the differences between graph and relational from the perspective of the known information requirements of health query. It reaches a conclusion as a result.

The starting point is to examine a few key logical differences then move on to some technical differences. Following this they are compared and contrasted from the perspective of the type of queries needed, in order to conclude which one to go for.

Firstly, its worth noting that a pure Graph model is not included for consideration. There are known problems at scale with pure graphs. If one were to adopt Graph then a property graph is the most likely variant. A property graph has properties on the nodes, and in the case of NEO4J, also has properties on the edges (which are called relationships).

Graph and relational relationships

Taking some very simple entity relationships from a health record, the following illustrates the different logical approach.  Graph is on the left, relational is on the right.

Graph versus relational.jpeg

The logical difference is that graph's can be explicit about a type of relationship between entities whereas a relational model uses foreign keys to link entities together i.e. the field on the right "patient id" points to the patient entity on the left but does not state the semantic reason for the link. On the left the graph states that a patient is a subject of an encounter, and could conversely indicated that an encounter has a subject that is a patient. The Graph approach is much clearer and much more intuitive. Graphs score highly. A graph is therefore more relational than a relational database.

The following diagram illustrates the processes involved in traversing from a patient to an observation (graph) versus a join between a patient and an observation, in both case using the encounter as an intermediate entity (accepting that in reality there may be  more direct relationship.