Basic graph data modeling

Basics of graph data modeling.

To get started with graph database concepts, let's explore the world is food as a graph:
Figure 1: Recipe Toy Graph
This graph, like many property graphs, is comprised of several subgraphs. For instance, one set of vertices and edges apply to food tracking by a person, while another set of vertices and edges apply to the distribution of ingredients amongst homes and stores. A recipe database is embedded within the data model, and links to recipes in cookbooks extend that portion of the model to allow for applications that can recommend cookbooks based on recipe choices. An obvious subgraph connects people to the cookbooks they author.
Examine the basic unit of a graph, a single edge connecting two vertices of different types. For this data model, a person (vertex label) created (edge) a recipe (vertex label). The properties are name, used for both a person and a recipe, and createDate used as an edge property for created.
Figure 2: Generalized data model for author and recipe
A generalized data model represents instances of each of the elements. Julia Child was a famous chef who created many recipes. One of the recipes she created for an American audience in 1961 was beef bourguignon. The diagram below captures the essence of this information with two vertices, one edge and the vertex property name and edge property create_date.
Figure 3: Julia Child creates beef bourguignon

DSE Graph supports multiplicity for both properties and edges. A single vertex can have multiple properties with the same property key. Properties default to a single values, but multiple values can be defined in the schema. If a vertex property requires its own properties, a meta-property can be defined. A graph can have multiple edges with the same edge label between a given pair of vertices. Multiple edges between two given vertices is the default, but the schema can define an edge label to support unique single edges between two given vertices.

Looking at the full data model, a person vertex can have a name, as well as additional properties such as gender and nickname. A reviewed edge can have a multiple properties that identify attributes of a recipe review for the adjoining recipe. Or consider the locations that a person has lived during their lifetime; a query can be aimed at discovering where a person lived. Would it be interesting to know if Julia Child lived in France or the United States while writing her first cookbook? It could be relevant if the cookbook is on French cuisine. Meta-properties start_date and end_date can pinpoint the required data. Since Julia Child lived in multiple countries during her lifetime, the property country must be a multi-property to store multiple countries with respective start and end dates.

You may wonder about deciding which entities and relationships are included in a graph data model. Let's take a look in the next section.