Introduction for Neo4j Graph Database

 

What is Neo4j Graph Database

 

Neo4j Graph Database is a native graph database from the company neo4j. It is one of the most famous graph databases in the market, where the database is optimized for OLTP (Online Transaction Processing) and data science workloads.

Neo4j database leverages its performance with distributed cluster architecture that scales with the data while maintaining low costs and hardware requirements. Its performance is trusted by many reputable companies like Airbnb, AstraZeneca, Volvo, and Allianz.

 

Graph Database

 

So what exactly is a graph database? A graph database is a type of NoSQL database, where it uses graph structures for semantic queries with nodes, edges, and properties. The graph database is created to overcome the limitations of relational databases.

For example, the graph database uses a graph model to show the dependencies between data nodes, while NoSQL databases use database models to link the data by implicit connections. In simpler words, relationships are an attribute in a graph database, where you can define and give properties.

 

Nodes

 

There are a few significant differences between the Neo4j database compared to a relational database. First, while "table" is to store data, Neo4j uses "node."

Since Neo4j is a type of NoSQL database, there will be no need to pre-define the table schema and the relation between the tables.

 

Relationships

 

As I have explained in the previous paragraph, relationships can be defined and assigned properties. I have created an example of a relationship. As the image above, we have two people (same node type), Kevin Mun and John Doe.

The relationship between both of them is "IS_FRIENDS_WITH." Since every node is isolate, there will be no problem for one to have a relationship with another. Unlike in a relationship database, defining a relation between data in the same table will be troublesome.

Relationships can be defined between any node without any limitations, and we will be able to retrieve the data with relationships with cheap cost queries. On top of that, we will be able to query the relationship, which allows us to retrieve the node's data by just knowing the relationship.

 

Cypher Query Language

 

Cypher is a query language to interact with Neo4j databases. While Cypher is created to simplify queries, it is also understandable by just reading through the query. Cypher is declarative and heavily inspired by SQL. The basic syntax is easy to learn, while it also unlocks the potential for users to construct complex queries efficiently in an expressive way.

Example of SQL

"select * from person"

“select * from person where name = ‘Kevin Mun’”

Example of Cypher Query 

"match (p:Person) return p"

"match (p:person {name:"Kevin Mun"})

match (c:person {name:"John Doe"})

create (p)-[r:IS_FRIENDS_WITH]->(c)

return r"

 

Neo4j Desktop

 

Neo4j Desktop is a free application that allows us to interact with our Neo4j databases. It works similarly to most database management studios, but comes with something extra. It has a gallery that offers plugins that can be installed, like Microsoft Visual Studio Code. It also comes with IntelliSense which assists us to complete the query by suggesting the name of nodes, relationships, as well as the value within.

Once we are connected to our databases, we will be able to see our available node types and the relationship types. When we execute our query, we will be given the choice to view the data as a table, plain text or the most unique way, as visual graphs, such as the image below:

 

Limitations

 

Though the Neo4j database is powerful, it is not widely accepted as the developer's first choice database. Moreover, it still needs time to garner higher popularity. Most Cloud service providers such as AWS, GCP, and Azure don't have native support for the Neo4j database on their databases services. Though we still can host on their platform, it needs more work to be done.

 

Final Note

 

Neo4j database is a fresh experience for me, and I have been using it for more than a year in an enterprise-level application; so far, it does serve most of our needs. Maybe it is worth spending some time on it for a brief understanding.

 


Popular posts

Archives