{"id":896,"date":"2016-06-16T22:19:42","date_gmt":"2016-06-17T05:19:42","guid":{"rendered":"https:\/\/database.guide\/?p=896"},"modified":"2023-02-14T12:45:59","modified_gmt":"2023-02-14T02:45:59","slug":"what-is-a-graph-database","status":"publish","type":"post","link":"https:\/\/database.guide\/what-is-a-graph-database\/","title":{"rendered":"What is a Graph Database?"},"content":{"rendered":"<p>A <dfn>graph database<\/dfn> is a database that uses a graphical\u00a0model to\u00a0represent and store the data.<\/p>\n<p>The graph database model is an alternative to the relational model.<\/p>\n<p>In a\u00a0relational database,\u00a0data is stored in\u00a0tables using a rigid structure with a predefined schema.<\/p>\n<p>In a graph database, there is no predefined schema as such. Rather, any\u00a0schema is simply a reflection of the data that has been entered. As more varied data is entered, the schema grows accordingly.<\/p>\n<p><!--more--><\/p>\n<h2>What does a Graph Database Look Like?<\/h2>\n<p>Here&#8217;s an example of a simple graph database.<\/p>\n<figure id=\"attachment_903\" aria-describedby=\"caption-attachment-903\" style=\"width: 440px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_relationship_example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-903\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_relationship_example.png\" alt=\"Screenshot of a simple graph database.\" width=\"450\" height=\"432\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_relationship_example.png 450w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_relationship_example-300x288.png 300w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><figcaption id=\"caption-attachment-903\" class=\"wp-caption-text\">Example of a simple graph database.<\/figcaption><\/figure>\n<p>The blue and green circles are <em>nodes<\/em>. The arrows represent\u00a0<em>relationships<\/em>.<\/p>\n<p>You can immediately see that\u00a0the relationship that Tom Hanks has with all those\u00a0movies (i.e. the green circles) is that he&#8217;s acted in them. But he also has\u00a0directed a movie that he has acted in, so\u00a0he has two relationships with that particular movie.<\/p>\n<p>Actually, this is not the full database. It&#8217;s just the results of a query from the sample Movie database supplied with the <a href=\"http:\/\/neo4j.com\/\">Neo4j<\/a> graph database management system.<\/p>\n<h2>Do Graph Databases use SQL?<\/h2>\n<p>Most graph database management systems are NoSQL systems, meaning, they either don&#8217;t support SQL, or they do, but also support other query languages.<\/p>\n<p>NoSQL originally meant &#8220;Non SQL&#8221; but this is sometimes\u00a0expanded to mean &#8220;Not only SQL&#8221;.<\/p>\n<p>In most cases,\u00a0SQL doesn&#8217;t make sense with the graph architecture. Graph databases are typically structured a lot\u00a0differently to the relational model that SQL was designed for.<\/p>\n<p>Many graph database management systems use\u00a0their own proprietary query language.<\/p>\n<p>The graph in the previous\u00a0example was generated from the following query:<\/p>\n<pre><span class=\"prompt code ng-scope\">$<\/span><span class=\"code mono ng-binding\">MATCH (tom:Person {name: \"Tom Hanks\"})-[:ACTED_IN]-&gt;(tomHanksMovies) RETURN tom,tomHanksMovies<\/span><\/pre>\n<p>That code is written in Cypher &#8211; the proprietary query language for Neo4j.<\/p>\n<p>Some graph database systems support other\u00a0languages such as JavaScript, JSON, XQuery,\u00a0SPARQL, etc<\/p>\n<h2>Graph Database Management Systems (GDBMS)<\/h2>\n<p>Graph databases are created and managed using a database management system (<a href=\"https:\/\/database.guide\/what-is-a-dbms\/\">DBMS<\/a>) specifically designed for graph databases. These can be\u00a0referred to as a Graph Database Management System\u00a0(GDBMS)\u00a0or\u00a0a Graph DBMS.<\/p>\n<p>Some\u00a0GDBMSs use a relational\u00a0storage engine, while the NoSQL systems\u00a0typically use a completely different architecture for their storage engine, for example\u00a0a <a href=\"https:\/\/database.guide\/what-is-a-key-value-database\/\">key-value store<\/a> or <a href=\"https:\/\/database.guide\/what-is-a-document-store-database\/\">document-oriented database<\/a>.<\/p>\n<p>Many NoSQL database systems use \u00a0<i>tags<\/i> or <i>properties<\/i>\u00a0to define relationships between nodes. This can help return large amounts of related data without the need to use joins across many tables, as one would be required to do using the relational model using SQL.<\/p>\n<h3>Example of a Graph DBMS<\/h3>\n<p>Here&#8217;s another example of some query results using the Neo4j graph database management system. This time showing the user interface.<\/p>\n<figure id=\"attachment_907\" aria-describedby=\"caption-attachment-907\" style=\"width: 890px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-907\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example.png\" alt=\"Screenshot of query results in the Neo4j graph database.\" width=\"900\" height=\"716\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example.png 900w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example-300x239.png 300w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example-768x611.png 768w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/graph_database_query_example-676x538.png 676w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><figcaption id=\"caption-attachment-907\" class=\"wp-caption-text\">Example of query results in the Neo4j graph database. The results show the nodes (blue and green circles) and the relationships (arrows) between them.<\/figcaption><\/figure>\n<p>The graphical representation of data in a graph database is in contrast to the tabular structure presented in the commonly used relational database\u00a0model.<\/p>\n<h3>Example of a Relational DBMS<\/h3>\n<p>Just for a comparison, here&#8217;s an example of a query in <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a>\u00a0(a <em>relational<\/em> DBMS). Note the results are displayed in a tabular format (as opposed to the\u00a0nodes and arrows that the graph model uses).<\/p>\n<figure id=\"attachment_902\" aria-describedby=\"caption-attachment-902\" style=\"width: 386px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/mysql_rdbms_query_join_example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-902 size-full\" src=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/mysql_rdbms_query_join_example.png\" alt=\"Screenshot of running a query in MySQL Workbench.\" width=\"396\" height=\"416\" srcset=\"https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/mysql_rdbms_query_join_example.png 396w, https:\/\/database.guide\/wp-content\/uploads\/2016\/06\/mysql_rdbms_query_join_example-286x300.png 286w\" sizes=\"auto, (max-width: 396px) 100vw, 396px\" \/><\/a><figcaption id=\"caption-attachment-902\" class=\"wp-caption-text\">A query in MySQL Workbench. The query results are provided in a tabular format.<\/figcaption><\/figure>\n<h2>Benefits of Graph Databases<\/h2>\n<p>Graph databases can have many benefits over other types of databases, and in particular, relational databases.<\/p>\n<h3>Performance<\/h3>\n<p>Graph databases can have major performance benefits over relational databases, particularly when it comes to large queries across\u00a0related data.<\/p>\n<p>Relational\u00a0database applications commonly have queries that join many tables &#8211; perhaps 20, 30, or more. Queries like this can run extremely slowly, especially as more and more records are entered into the database. Recursive queries can be a particular issue, especially if they run many levels deep.<\/p>\n<p>In many cases, if that same data was stored in a graph database, the queries would be much simpler and they would run much quicker.\u00a0This is because, on a graph database, queries are localised to a portion of the graph. This means that the\u00a0execution time for each query is proportional only to the size of the part of the graph traversed to satisfy that query, rather than the size of the overall graph.<\/p>\n<p>Of course, this all depends on the data.\u00a0The graph model is not necessarily the ideal model for all cases. Some data is more suited to the tabular structure of relational databases. However, the graph model is well suited to querying\u00a0large associative data sets.<\/p>\n<h3>Flexibility<\/h3>\n<p>Because there&#8217;s no need to define a set schema, you have complete flexibility over how the database grows.<\/p>\n<p>With the\u00a0relational model, you would need to map out the requirements in full detail before creating the database. You need to try to foresee\u00a0any potential change in business requirements and try to build a solution that caters for all possible future scenarios. This is not always possible.\u00a0If the business requirements\u00a0grow\/change\u00a0significantly, the structure of the database may also need to change significantly. It may even have to be completely redone.<\/p>\n<p>With the graph model, as the business grows, you can always\u00a0add new types\u00a0of relationships, new nodes, and new subgraphs to any existing database\u00a0without disturbing existing queries and application functionality.<\/p>\n<h3>Development and Maintenance<\/h3>\n<p>Software development has\u00a0evolved to a point where it&#8217;s standard practice to release updates\u00a0incrementally and iteratively. This is in contrast to the major release cycle that often took many months or even years.<\/p>\n<p>Graph databases are well suited to this incremental\/iterative release practice, because\u00a0no underlying structural changes need to take place before any changes can occur on the application.<\/p>\n<h2>What can a Graph\u00a0Database be used for?<\/h2>\n<p>Graph databases can be used in\u00a0a wide variety of applications. Some popular uses for graph databases include:<\/p>\n<ul>\n<li>Social networks<\/li>\n<li>Realtime product recommendations<\/li>\n<li>Network diagrams<\/li>\n<li>Fraud detection<\/li>\n<li>Access management<\/li>\n<li>Graph based search of digital assets<\/li>\n<li>Master data management<\/li>\n<\/ul>\n<h2>Examples of Graph Databases<\/h2>\n<p>Examples of graph databases include\u00a0<a href=\"http:\/\/neo4j.com\/\">Neo4j<\/a>,\u00a0<a href=\"https:\/\/www.blazegraph.com\/\">Blazegraph<\/a>, and\u00a0<a href=\"http:\/\/orientdb.com\/\">OrientDB<\/a>.<\/p>\n<p>Check out this list of <a href=\"https:\/\/database.guide\/list-of-graph-database-management-systems\/\">over 40 graph DBMS<\/a>s.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A graph database is a database that uses a graphical\u00a0model to\u00a0represent and store the data. The graph database model is an alternative to the relational model. In a\u00a0relational database,\u00a0data is stored in\u00a0tables using a rigid structure with a predefined schema. In a graph database, there is no predefined schema as such. Rather, any\u00a0schema is simply &#8230; <a title=\"What is a Graph Database?\" class=\"read-more\" href=\"https:\/\/database.guide\/what-is-a-graph-database\/\" aria-label=\"Read more about What is a Graph Database?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,43],"tags":[18,166,167,20],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-database-concepts","category-nosql","tag-database-terms","tag-define","tag-definition","tag-what-is"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=896"}],"version-history":[{"count":8,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":1107,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/896\/revisions\/1107"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}