What is Graph and why use Graph database?

What is Graph ?

Everything in the world is connected. Every person, object, thing has connection to other things. To display this inter-connection between things, we use Graph.

The Graph theory emerged in 1736, when Leonhard Euler gave negative resolution to Seven Bridges of Königsberg problem. The city of Königsberg in Prussia (now Kaliningrad, Russia) was set on both sides of the Pregel River, and included two large islands which were connected to each other, or to the two mainland portions of the city, by seven bridges. The problem was to devise a walk through the city that would cross each of those bridges once and only once. watch this excellent video – Seven bridges of Königsberg.

  • Seven Bridges of Konigsberg Problem:
    • 4 Vertices/Nodes (4 areas of town), 7 Edges (7 bridges)
    • Euler proved that this can’t be resolved – no one can traverse the bridge by passing each bridge only once. He gave some rules/properties – like if exactly zero or two vertices have odd degree, and all of its vertices with nonzero degree belong to a single connected component, then each vertex can be traversed only once.
    • In 1875, the city built another bridge between the nodes B and C. This resulted in only two vertices with an odd degree, which solved the impossible walking problem!
    • But unfortunately, two of the original bridges were destroyed in 1942, during WWII.

What is Graph Database?

A pictorial representation where things are represented by nodes/vertices and their inter-connection by edges between nodes. Graph database is used to model the data in the form of graph.

Why use Graph DB?

When the relationship/inter-connectedness between the data is more important and valuable, we use GraphDB. Relational Databases like MySQL, Oracle etc are used to store structured data, and don’t store relationships between the data (though relationships can be found using JOIN Queries – it becomes drastically slow – check the image below). Unlike relational and other NoSQL databases, Graph DBs store relationships and connections as first-class citizens. Few benefits of using GraphDB:

  • Data retrieval is incredibly efficient for connected data. Query speed even for deep and complex queries is blazingly fast (1000x faster in some cases)
  • It is required when you want cohesive picture of data, including the connections between elements.

In their book “Neo4j in action”, the authors performed experiment between RDBMS and Neo4j, and here are the results:

RDBMS vs Neo4j

RDBMS vs Neo4j (Source: Graph databases for Beginners by Neo4j)

Popular Graph databases

Some of the popular graph DBs are given below –  complete list

  • Oracle NoSQL DB
  • HyphergraphDB
  • GraphBase
  • AllegroGraph
  • Orient DB

 See next section on “Why NOT RDBMS for connected data?