In our time, there is a great variety of data in the world. Developers often have to work with incomplete or isolated, or tightly connected information. So, it seems convenient to use specialized methods of storing and processing data. In this topic, you will learn about the advantages and disadvantages of a Graph Database. Also, you will take a look at the problem it solves.
How is a Graph Database organized?
Let's remind ourselves that a Graph is a set of nodes and relationships between them. This structure allows you to simulate all kinds of scenarios, from the university schedule to the nuclear half-life process.
Graph Databases use nodes to store data entities and edges to store relationships between entities. Edges always have a start node, an end node, and a direction. Nodes contain properties and can be linked to any number of other nodes. Like nodes, relationships can also have properties. This is useful for adding some data (like quality and weight) to relationships, for instance, to optimize a graph algorithm's work.
There are two main types of graph data models: Property Graph and RDF – Resource Description Framework.
A Property Graph is a directed graph in which vertices correspond to "records" and edges correspond to "connections" between them. Additionally, both edges and links can be provided with attributes. The most well-known query language is Cypher, supported by Neo4j.
RDF is a graph format presented in the form of the "subject – predicate – object" triples. The model copes well with unstructured data. RDF triples can be packed into one general graph. SPARQL is the most common and cross-platform query language.
Getting closer to the application
As you can see above, the structure of Graph Database is very different from the SQL-data model. Let's see in what cases such a structure is really the most optimal.
The most particular example of graphs in development is the graph of a social network, which displays friendly relations between people, their taste preferences, and so on. Now almost all popular social networks store part of the information using graph databases.
In addition, Graph Databases are a good choice for recommendation systems. Using a graph database, you can store relationships between the interests of the buyers and their purchase history. With the graph database, you can recommend products to users based on choices by other users, who are interested in the same sport and have a similar purchase history.
Graph databases are also actively used in bioinformatics and for the formation of the Semantic Web. RDF graphs are used in the semantic search (search by meaning).
Obviously, if it is necessary to save and use various relationships between entities, graph databases look like a fairly native choice. Here are more advantages of the model:
Flexibility – when using graph storage, data can be easily converted from one model to another;
Scalability – adding new objects and connections does not require changing the existing structure;
Speed – traversing connections or relationships in graph databases is performed very quickly, because the relationships between nodes are not calculated during query execution, but are stored in the database.
Of course, there are some disadvantages:
Absence of a single standard resulting in dependency on the specific implementation.
It requires more memory because it stores not only entities but also the relationships between them.
Most of the existing graph databases initially work slower than the relational ones.
Every medal has its reverse. Think carefully if you want to use Graph Database in your project. With proper use, it will greatly increase the query execution rate. In the opposite case, the efficiency will drop. And there will also be a lot of friction.
Glorified or forgotten with time?
To sum up, it is not clear yet, whether graph databases will gain the same popularity as relational databases, or even win by efficiency and nativity. Like any concept, they have advantages, and, unfortunately, disadvantages. Anyway, now it is a very effective and actively used tool for solving specialized problems.