Relational modeling versus graph modeling
We have two options to store the data if we adopt a relational modeling point of view:
- Store the source and destination of an edge (relationship) as a row, and do that for all the edges, as shown in (a) in Figure 5.19. When you need to find the outgoing edges (whom a particular user follows), you can use an index to “seek” the start of that user’s outbound relationships.
- Store an edge twice and add another column to indicate the direction, as shown in (b) in Figure 5.19.
Figure 5.19: A diagram showing the options to store graph data using a relational model
Graph modeling
Now, if we want to store data using graph modeling, we would represent the data in doubly linked list graphs and two tables, called nodes
and relationships
:
- Figure 5.20 (a) represents nodes and their relations as doubly linked lists. We have three nodes, hence three linked lists.
- Figure 5.20...