A brief overview of Graph Databases
A database is one that can store and retrieve data from a computer. Today all databases are based on either RDBMS(SQL) or NoSQL DB.
SQL vs NoSQL
In relational databases, data is stored in tables containing multiple records (rows). These tables are connected to each other using one or more relations. Examples includes MySQL, Postgres, Oracle, MSSQL, e.t.c.
Unlike relational databases, non-relational databases — NoSQL databases — don’t store data in tables and records. Instead, the data storage structure in these databases is designed and optimized for specific requirements. Examples include MongoDB, CosmosDB, Redis, Cassandra, and so forth.
When to use SQL
When working with complex queries and reports.
You have a high transaction application.
You need to ensure ACID compliance. with Consistency being Strict, not eventual.
You don’t anticipate a lot of changes or growth.
Working with strict schema design, for example:
public class User {
private Long id;
private String name;
private String age;
private List<Transaction> transaction;
}
When to Use NoSql
Working with a highly flexible schema design or no predefined schema with constant new features, functions, and data types, for example:
user = {
_id: “1”,
name: “covy”,
age: 79,
transaction: [
{
amount: “50”
}]
}
You are not concerned about strict data consistency, and 100% data integrity is not your top goal.
You have a lot of data with different data types, and your data needs will only grow over time.
Your data needs to scale up, out, and down.
There are four popular types of NoSQL databases, they are column-oriented, document-oriented, key-value pairs, and graph databases.
What is a Graph Database
When you hear the word graph, your mind probably takes you to graphs plotted in high school, and it isn’t far-fetched. Take a look at the image below.
This simple graph does one thing in particular, it shows the relationship between the “Number of supplies” vs the “Types of school supplies”. This is what a Graph Database is all about. It is all about relationships between entities. Entities can be a cup, the wind, a salary, anything. In Graph Dbs, Relationships are called Edges, and Entities are called nodes or vertexes.
Why Graph DBs
In SQL DBs, one can save relationships or joins. There are the one-many, one-one, many-many relationships, e.t.c. A Graph DB stands out because it is very fast for traversing joins or relationships. The relationships between nodes are not calculated at query times but are persisted in the database. A simple proof is seen in the image below.
I ran a simple getAllTransactionsFromUserAWhereAmountIsBetween 1 and 10 for all three according to their syntaxes.
When to use a GraphDB
When you want to flag fraud rings by analyzing patterns between entity relationships.
When you want to create a social media or network graph.
When you want to build a knowledge graph to get deeper contexts for insights.
For Identity Management.
Read more here: https://www.oracle.com/a/ocom/docs/graph-database-use-cases-ebook.pdf
Two examples of GraphDB: Neo4J vs Nebula
Neo4j is owned by Neo4j inc. They are ACID compliant, They make use of cypher for their query and support languages like Java, Python, Go, .Net, and NodeJs. Read more below.
Nebula-Graph is owned by Vesoft. It is open source, it makes use of its own query language but is becoming compatible with cypher queries. They support Languages like Java, Python, Go, C++ and NodeJs.
I found both Nebula-Graph Studio and Neo4J browsers easy to start up, but the Neo4J browser is a bit more difficult to use than Nebula. Neo4J has clearer documentation but is less exhaustive in comparison with Nebula-Graph. To learn more about their performance differences, you can check :
For Java developers
If you are using a SpringBoot Application, you might want to go with Neo4J as it has its dependency. But, If not, please go with Nebula-graph. Nebula-graph supports JPA, which is one BIG plus for them.