{"id":280913,"date":"2021-06-22T20:00:00","date_gmt":"2021-06-22T17:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-is-a-graph-database-and-what-is-it-used-for-cloudsavvy-it\/"},"modified":"2021-06-22T20:00:00","modified_gmt":"2021-06-22T17:00:00","slug":"what-is-a-graph-database-and-what-is-it-used-for-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-is-a-graph-database-and-what-is-it-used-for-cloudsavvy-it\/","title":{"rendered":"#What Is a Graph Database, and What Is It Used for? \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2c0b3d53dc9\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2c0b3d53dc9\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-a-graph-database-and-what-is-it-used-for-cloudsavvy-it\/#What_Is_a_Graph_Database\" >What Is a Graph Database?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/what-is-a-graph-database-and-what-is-it-used-for-cloudsavvy-it\/#What_Makes_Them_Faster\" >What Makes Them Faster?<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#What Is a Graph Database, and What Is It Used for? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<figure style=\"width: 1000px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage wp-image-4341 size-full\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/3f39d86a-e1586185970284.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Graph Database Idea\" width=\"1000\" height=\"474\" src=\"https:\/\/www.shutterstock.com\/image-illustration\/futuristic-abstract-blue-network-data-connection-1228741030\" data-credittext=\"Eduard Muzhevskyi\/Shutterstock\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><figcaption class=\"wp-caption-text\"><span class=\"type:primaryImage imagecredit\"><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.shutterstock.com\/image-illustration\/futuristic-abstract-blue-network-data-connection-1228741030\">Eduard Muzhevskyi\/Shutterstock<\/a><\/span><\/figcaption><\/figure>\n<p>Graph databases are a special kind of database storing complex data structures that would be infeasible to store in a traditional relational database. They\u2019re most notably used for <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">social<\/a> networks, as they\u2019re much more performant for certain queries.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_a_Graph_Database\"><\/span>What Is a Graph Database?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Graph databases are most commonly used for highly interconnected data, and for situations where the content of the data itself matters less than the overall structure.<\/p>\n<p>The most straightforward use case for graph data is for social networks. Consider a network of people; each person has a friends list and has relations to other people. Each person also makes posts, often hundreds of them. Every post could have thousands of people interacting with it. So, despite the tweet only being 280 characters long, there\u2019s so much more to store about it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" alignnone wp-image-326 size-full\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/05\/8e629038.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A graph data base of a network of people are interconnected as friends. Each person enters a post with which all friends can interact.\" width=\"700\" height=\"300\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This certainly isn\u2019t the only use case, just the most digestible one\u2014graph databases are used for all sorts of things. Another example is fraud detection; say you\u2019re a bank, and want to flag suspicious accounts. It might be a little fishy for two separate accounts to have the same address or share phone numbers. With a graph database, you can make a graph of the connection between the two accounts, and identify problems like this much more efficiently than a relational database ever could.<\/p>\n<p>In a graph database, each object is called a node. A node can have any number of properties, very similar to how a document database works. A document database would simply store each node as a separate document in a collection (array) of documents, without taking into account how they connect.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" alignnone wp-image-2192 size-full\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/3b3431f3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A graph database with several nodes or objects and their connections known as edges.\" width=\"700\" height=\"300\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>In a graph database, the connections between the nodes are called\u00a0<em>edges<\/em>, and they can connect any two nodes from anywhere in the table. Edges define the relationships between nodes, and can have specific types. For example, two friends would be connected with a \u201cFriends\u201d edge, but a user would be connected to a post with a \u201cPosted\u201d or \u201cLiked\u201d edge.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Makes_Them_Faster\"><\/span>What Makes Them Faster?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s not that relational databases like MySQL <em>can\u2019t<\/em> store graph-like structures\u2014links like these are still core concepts for SQL tables. Links form connections between tables, enabling data to be stored and updated in separate tables while maintaining a link elsewhere in the database, very similar to how pointers work in C.\u00a0 In the social network example, you wouldn\u2019t want to store the name of every friend a given user has as that friend can change their name, so you instead store the friend\u2019s ID, and then perform a lookup whenever you need the right data. Perhaps you cache the results to take some load of the database, but most systems will work similarly to this.<\/p>\n<p>Storing one set of links (like a friends list) is fine, but the problem comes when you start to do any type of complex analysis. The classic example is the friends-of-friends search. To obtain a list of everyone who has a mutual friend with the given person, you would need to loop over the given person\u2019s friends list, and then loop over each friend\u2019s friends list, and then perform a lookup for each record. You\u2019ve also got to make sure you\u2019re not returning duplicate records, which is an extra loop.<\/p>\n<p>If you\u2019re familiar with <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/Big_O_notation\">Big O Notation<\/a>, you may see the issue here already. It\u2019s a problem with exponential complexity; doing multiple nested loops like this breaks the computer very quickly. It also isn\u2019t a smart way to go about this problem.<\/p>\n<p>Take a look at this benchmark of neo4j running the friends-of-friends query, compared to a traditional relational database (like MySQL):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2168 size-full\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/a8807243.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A neo4j benchmark\" width=\"700\" height=\"312\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>At depth 2, it\u2019s a simple query for both databases. At depth 3, MySQL becomes unable to perform this query in a normal timeframe, taking 30 seconds to return a response. To its credit, it manages to return the depth 4 query after 25 minutes, though depth 5 crashes the database.<\/p>\n<p>The graph database has no problem returning any of these queries, with all execution times being under 2 seconds, making it thousands of times faster.<\/p>\n<p>How does it do this? Very complicated math, mostly. Graphs are a mathematical structure at heart, and there\u2019s <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/Graph_theory\">a lot of theory<\/a> behind it, which we\u2019re thoroughly unqualified to discuss in detail. But relational graphs are fairly simple to understand visually, which makes working with graph databases in practice easy.<\/p>\n<p>If you want to get started working with one, you\u2019ll have to pick and install a graph database. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/neo4j.com\/\">Neo4j<\/a> is free and open source, and a very popular option. AWS has their Neptune database, which you can try for free, but must host on AWS. Some multi-model databases support graphs as an option, such as <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.microsoft.com\/en-us\/sql-server\/default.aspx\">Microsoft SQL Server<\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/redirect.viglink.com\/?key=204a528a336ede4177fff0d84a044482&amp;u=https%3A%2F%2Fwww.oracle.com%2Fdatabase%2F\">Oracle Database<\/a>, and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.arangodb.com\/\">ArangoDB<\/a>.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/2185\/what-is-a-graph-database-and-what-is-it-used-for\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#What Is a Graph Database, and What Is It Used for? \u2013 CloudSavvy IT&#8221; Eduard Muzhevskyi\/Shutterstock Graph databases are a special kind of database storing complex data structures that would be infeasible to store in a traditional relational database. They\u2019re most notably used for social networks, as they\u2019re much more performant for certain queries. What&#8230;<\/p>\n","protected":false},"author":1,"featured_media":280914,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/10\/3f39d86a-e1586185970284.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-280913","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/280913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=280913"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/280913\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/280914"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=280913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=280913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=280913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}