Graph database — NoSQL database
The third category of NoSQL database that we are going to discuss is graph database.
What is graph database and how is it used?
A graph database uses nodes, edges to represent and store data in a database. The collection of nodes and edges in the graph are data items in store, where the edges represent relationship between nodes. This relationship allows data that is linked together to be fetched with one operation.
Need for graph databases: We live in a connected world and graph database is purposefully built to handle highly connected data. The relationship between items is as important as the item itself. While existing relational databases can store relations, we navigate them by performing expensive joins or cross-lookups. It looks like relational databases are bad in handling relations, but the good news is that graph databases are good in handling relations as no expensive joins or lookups are needed to navigate the relations.
Graph databases can be used to discover hidden connections between distant items and navigate deep hierarchies. Whether it is social network, road network or payment network, everything is interconnected graph of relationships and can be represented using graphs.
Nodes are instances in graph where nodes can hold any number of key-value pairs or properties or meta data. Nodes can be tagged as labels representing their role in the graph.
Edges provide directed, named connection between two entities. Edges always have direction, start node, end node and they can have properties(for ex: person A lives in house since 2016 where person A and house are entities, lives is relationship and since 2016 is property). Any number of relations can exist between instances without affecting performance.
Advantages:
- Performance: For intensive data relations handling, graph database provide performance several orders of magnitude more than relational databases. With traditional databases, relationship queries comes to a grinding halt with increasing data and depth of relations but graph databases gives constant performance even with increasing data.
- Flexibility: Changing the structure and schema of graph database is flexible as company demands change. But in traditional databases, schema modeling is done ahead of time and changing structure of database becomes time-consuming process later on.
- Real time data update: Graph databases can perform real-time updates while supporting queries simultaneously. In big data management systems, appending and querying is part of workload where any query would touch majority of file, while graph database only touch relevant data.
Disadvantages:
- No standardized query language. Every platform has their own language
- Graphs don’t work for transaction-based systems.
Use cases:
- Real-time recommendation system: This is used by major tech giants like Netflix, Walmart to provide recommendations for better user experience. How does it work: Preferences of every person are stored in graph database. Suppose, person A and person B have one common preference, this creates a relationship between A and B and all the preferences of A are suggested to B and vice versa.
- Connection recommendation system: This is used by major tech giants like facebook, instagram to provide friend recommendation by suggesting connections of a person to every connection as mutual friends.
- Routing: Information is sent over the internet by finding optimal paths with the help of graph database. Algorithm: shortest path between two nodes — Dijkstra’s and BFS
Best graph databases: Neo4j, ArangoDB, FlockDB
Summary: Graph database provides excellent performance for analyzing complex relationships among entities.There are many more enhancements yet to come in graphs.
The next blog with cover last category of NoSQL database i.e. wide column store.
Thank you for checking out my blog! Subscribe to get notified on upcoming blogs!!