Introduction to Graph Databases

Introduction to Graph Databases
Photo by Uriel SC / Unsplash

1. Introduction

Have you ever heard of "Graph Databases - Graph Database"? Are they databases used to store pictures? Or are they databases that store data in the form of pictures? (Misconception) If you have been misled by these two sentences, then let's get into today's article.

2. Nodes and Relationships

Unlike traditional relational databases, graph databases consist of nodes and relationships (the connections between nodes). As shown in the figure below:

Nodes and Relationships

2.1 Nodes

Nodes represent entities. A node is similar to a record in a relational database. In the above figure, the circular patterns represent nodes. The orange nodes represent movie entities, and the blue nodes represent specific individuals.

2.2 Relationships

The connection between two nodes is called a relationship. In the aforementioned figure, three types of "person-movie" relationships are present:

  • ACTED_IN - Involves actors such as Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, and Hugo Weaving.
  • DIRECTED - Directed by the Wachowski sisters.
  • PRODUCED - Produced by Joel Silver.

2.3 Relationship Direction

In Neo4J, relationships have a direction. For a node, a relationship can have two directions: pointing to it or pointing from it to other nodes. In the above figure, all relationships are directed from a person to a movie.

2.4 Labels

Labels represent the type of a node or relationship. In the above figure, when defining blue nodes, their labels are "Person," and when defining orange nodes, their labels are "Movie." Labels serve the purpose of returning only specific types of nodes when querying. For example, querying only "Person" nodes.

Labels

2.5 Properties

Both nodes and relationships can have properties. Properties are added in the form of name-value pairs. For example, retrieving the name and birth year properties of all Person nodes in the above figure. Properties make the information in a graph database more rich, and they can also be utilized in queries, such as querying people born after 1970.

Properties

3. Why Graph Databases?

After getting a general introduction to graph databases, you may find this technology fascinating. What value can graph

databases bring to specific businesses that relational databases cannot? The following two aspects can serve as reference:

  • Efficiently query relationships between data, especially when the relationships are complex.
  • Conveniently visualize relationships between data.

When you see query results like the following, isn't it pleasing to the eye? The relationships between movies and people are clear at a glance. Of course, this is only a small part of the query results.

Visualization of Results - 1

As the data increases, the visualization results may look like this...

Visualization of Results - 2

Of course, no one would extract valuable information from such visualization results. So how should graph databases be applied in specific business scenarios? Stay tuned for the upcoming practical series on graph databases, which will give you a more concrete understanding of this innovative and trendy technology! I hope this sharing has been helpful to you.