DEV Community

Cover image for What is Graph Databases? A better way to store connected data
Iyvonne Bett
Iyvonne Bett

Posted on

What is Graph Databases? A better way to store connected data

Here in this article, I’ll discuss some ideas and concepts of graph databases, what they are, What you should know in order to pick the correct data store for your application(s) and how they can help us in our daily tasks.

What is a Graph?

A graph is a set of discrete objects, each of which has some set of relationships with other objects.

Alt Text

What is a Database?

From techopedia:
A database, in the most general sense, is an organized collection of data. More specifically, a database is an electronic system that allows data to be easily accessed, manipulated and updated.

In other words, a database is used by an organization as a method of storing, managing and retrieving information. Modern databases are managed using a database management system (DBMS).

What is a Graph Database?

A graph database contains a collection of nodes and edges. A node represents an object, and an edge represents the connection or relationship between two objects. Each node in a graph database is identified by a unique identifier that expresses key-value pairs. Additionally, each edge is defined by a unique identifier that details a starting or ending node, along with a set of properties.

Alt Text

Designed for working with highly interconnected data, Graph databases shine when the goal is to capture complex relationships in vast webs of information.
There are three types of graph database: true graph databases, triple stores and conventional databases that provide some graphical capabilities. Triple stores are often referred to as RDF databases.
Examples:
– Neo4j, OrientDB, InfiniteGraph, AllegroGraph.

Neo4j Databases
Neo4j offers a graph database that helps organizations make sense of their data by revealing how people, processes and systems are related. Neo4j natively stores interconnected data so it’s easier to decipher data. The property graph model also makes it easier for organizations to evolve machine learning and AI models. The platform supports high-performance graph queries on large datasets as well.
Neo4j can import tables into nodes from CSV files, create indexes on the nodes, create uniqueness constraints, and construct relationships using the Cypher query language.

Graph Databases: Pros and Cons

Pros:

  • Powerful data model, as general as RDBMS.
  • Connected data locally indexed.
  • Easy to query.

Cons:
  • Difficult to scale. Sharding ( lots of people working on this)
  • No standard language. Every graph database vendor has defined a unique syntax or language for updates and queries.
  • Requires rewiring your brain

Why You Should Care about Graph Database Technology?

Performance:

  • Your data volume will definitely increase in the future, but what’s going to increase at an even faster clip is the connections (or relationships) between your data. Big data will definitely get bigger, but connected data will grow exponentially.
  • With traditional databases, relationship queries come to a grinding halt as the number and depth of relationships increase. In contrast, graph database performance stays constant even as your data grows year over year.
  • Flexibility:

  • With graph databases, your data architecture teams move at the speed of business because the structure and schema of a graph data model flex as your solutions and industry change. Your team doesn’t have to exhaustively model your domain ahead of time (and then exhaustively remodel and migrate the DB after some exec asks for a change); instead, you can add to the existing structure without endangering current functionality.
  • With the graph database model, you are the one dictating changes and taking charge; whereas the RDBMS data model dictates it’s requirements to you, forcing you to adapt to its tabular way of seeing the world.
  • Agility:

  • Developing with graph technology aligns perfectly with today’s agile, test-driven development practices, allowing your graph-database-backed application to evolve with your changing business requirements. Your agile team now has a database that keeps up with your daily demands.
  • Graph database vs. relational database

    Relational databases are not well suited to capturing ad hoc relationships that are not consistent across all records: You wind up with sparsely populated rows and way too many indexes, both of which slow down the database performance. Remember, the relational schema is fixed, so every record in a given table contains every field, whether or not the field is populated.
    Moreover, In a conventional database, queries about relationships can take a long time to process. This is because relationships are implemented with foreign keys and queried by joining tables. As any SQL DBA can tell you, performing joins is expensive, especially when you must sort through large numbers of objects—or, worse, when you must join multiple tables to perform the sorts of indirect (e.g. “friend of a friend”) queries that graph databases excel at.
    Alt Text

    Graph databases work by storing the relationships along with the data. Because related nodes are physically linked in the database, accessing those relationships is as immediate as accessing the data itself. In other words, instead of calculating the relationship as relational databases must do, graph databases simply read the relationship from storage.

    It also allows you to build a knowledge graph. Because they are graphs, knowledge-graphs are more intuitive. People don’t think in tables, but they do immediately understand graphs. When you draw the structure of a knowledge graph on a whiteboard, it is obvious what it means to most people.

    Alt Text

    How to choose the Right Data Management Solution

    When Is a Graph Database the Right Fit?
    Graph databases are hardly a "one size fits all" solution. The type of data, use cases, and available resources should all be considered when deciding to move forward with the graph model or a more traditional data management solution, like the relational database.

    Graph databases are suited to handle the volume, variety, and velocity.
    Managing data as graphs is a particularly good fit when the use case involves modifying schemas and accommodating new features, data points, or sources.

    Graph databases are ideal for instances where elements will need to simultaneously relate to each other, be easily accessible, and query millions of relationships per second. Such data and data management systems are needed to integrate information for chatbots, conversational systems, social applications, recommendation algorithms, optimization applications, routing, and maps — all real-world interactions that need to be stored as densely connected structures and navigated seamlessly.

    AI and machine learning applications tremendously increase in value when configured to work against graph databases, because they can now understand and analyze the edges, or relationships, between entities within the dataset or the content set in the graph form.
    Graph databases also run more efficiently across highly-connected datasets. Other data management solutions usually cost more to run.

    Relational database: deal with more simple data models and connections for less connected static data.Example tabular data such as inventories, financial records.

    Graph database: deal with complex data models and processing of large dynamic networks of relationships Example social networks, content management.

    In Conclusion
    In this article, we have learned about graph databases. In the future, I’ll discuss how graph databases can help us do machine learning and data science in general. If you are interested in building a graph database or reading more I would suggest you start with the Neo4j website as they have excellent documentation in the area. Stay tuned for more.

    Top comments (3)

    Collapse
     
    lilithkarapetyan profile image
    Lilit Karapetyan

    Great article! It's wonderful how you explained all the things needed for the reader to understand this article, including graphs and relational databases! I had a little experience with neo4j, and I was in love with the desktop app. It provides excellent visualizations and essential tools for finding the relationship you need.
    Thank you for mentioning the use cases. It would be great also to have a comparison with the document-oriented NoSQL DBs for a complete picture, however, the article still is very informative and well explained!

    Collapse
     
    djnitehawk profile image
    Dĵ ΝιΓΞΗΛψΚ

    awesome intro to graph dbs!!!
    any plans to write a beginners guide/ article for neo4j by any chance?

    Collapse
     
    iyvonnebett profile image
    Iyvonne Bett

    Thank you. Yes, I'm planning to do that soon. Stay tuned.