{"id":49358,"date":"2016-01-25T00:00:00","date_gmt":"2016-01-25T00:00:00","guid":{"rendered":"https:\/\/www.techopedia.com\/how-graph-databases-bring-networking-to-data\/"},"modified":"2020-06-25T20:11:54","modified_gmt":"2020-06-25T20:11:54","slug":"how-graph-databases-bring-networking-to-data","status":"publish","type":"post","link":"https:\/\/www.techopedia.com\/2\/31571\/trends\/big-data\/how-graph-databases-bring-networking-to-data","title":{"rendered":"How Graph Databases Bring Networking to Data"},"content":{"rendered":"

Modern-day data-driven applications are largely dependent on relevant insights derived from the enormous volumes of data they handle every day. To gain better insights every time, the applications need to be able to send complex queries<\/a> and the database should be able to address complex queries. Traditional RDBMS<\/a> systems that rely on SQL<\/a> are unable to handle extremely complex queries. Graph databases<\/a> have been able to solve this problem because they rely on objects and the relationships between objects. Based on this premise, it is possible to extract deep insights. The use of graph databases, however, is still limited, although there are definite signs that it is going to play an important role as businesses rely more and more on insights to power their business. (For more on databases in general, see Introduction to Databases<\/a>.)<\/p>\n

What Is a Graph Database?<\/span><\/h2>\n

To understand graph databases, let us use the example below:<\/p>\n

Bill and his family want to plan a vacation to a place that offers great Asian cuisine. He has started planning early and one of the ways to find information is, of course, Google. While the information from Google is credible and good, for Bill, it is important to get as specific information as possible. So, he starts asking his friends, acquaintances and colleagues. Let us assume that Bill asks Ryan, Sheena and John, who are his primary contacts (contact level 1). All three promise to respond with information as soon as possible. Ryan asks his friend Greg, who asks his cousin Martin who has been to Bangkok a few times. Martin recommends the names and details of all his favorite eateries in Bangkok known for their Asian dishes. This information is relayed back to Bill.<\/p>\n

You have just seen a real-life example of a complex query based on objects and relationships. The graph database works on the same principle. It is about the network, the objects and their relationships in the network.<\/p>\n

Basically, a graph database is capable of extremely complex graphs and provides insights which SQL-query-based RDBMS systems cannot. And that is the unique selling point about graph databases.<\/p>\n

How Does a Graph Database Work?<\/span><\/h2>\n

The above description of a graph database gives some idea about the principles that a graph database applies when it searches for information or insights. Basically, it traverses the network of objects and relationships based on the query, and returns the results.<\/p>\n

If we take the above example of Bill, then how would a graph database go about its job? Obviously, there are a lot of relationships and nodes<\/a> in the example. If we see the distance of the relationships, it would look like the following:<\/p>\n

Bill = 0 (the origin)<\/p>\n

Ryan = 1<\/p>\n

Sheena = 1<\/p>\n

John = 1<\/p>\n

Greg = 2<\/p>\n

Martin = 3<\/p>\n

The distance between the origin (zero) and the node that provides the information could be even further in real life — that is how the network works.<\/p>\n

Imagine an application sending a query based on Bill’s requirement. It would be something like:<\/p>\n

Find all friends who are connected with five friends who like Asian food, who have visited Thailand and who live within 5 miles of Dallas.<\/em><\/p>\n

There are a lot of graph databases available in the market, and Neo4j is the most popular among them. Neo4j can attribute its popularity to the facts that it is both efficient and open source<\/a>. So, when you send a query to the Neo4j to solve Bill’s problem, the query could look something like:<\/p>\n

\/\/ select friends and friends of friends, keyword of Asian food, keyword of Bangkok, order by depth of the relationship<\/em><\/p>\n

String findFriendsQuery = "start n=node(*), person=node({userNode}) MATCH p = (person)-[:FRIEND*1..2]-(friend) return distinct p order by length(p)";<\/em><\/p>\n

Based on the query, Neo4j is going to search through its available network and find the closest matches.<\/p>\n

Difference Between Graph Databases and Relational Databases<\/span><\/h2>\n

The main point around which relational databases and graph databases are compared is the speed of transactions, that is, how fast can it process a complex query on a big data set<\/a>.<\/p>\n

Emil Eifrem, the CEO of Neo Technology, the company behind Neo4j, measured the performance of both relational and graph databases on multiple parameters. The query was: in 1,000 users with each user having 50 friends or more, find out if one user is connected to another in 4 or fewer hops. The results are given below:<\/p>\n