The first thought that comes to your head when you hear graphs is the dreadful graph theory from mathematics which further translates to boring, complex, and so on…
Luckily for us, we don’t need a lot of Graph theory to learn about Twitter’s database to connect 330 million monthly active users! But let’s have a look at an easy explanation for graphs.
Need for Graphs
Before the what, we always need to know the why. So, let’s dive straight into knowing “Why do we need graph databases?”
I’m sure you’ve heard about a relational database before. Let’s quickly sum it up.
- A relational database is made of foreign key constraints which simply means relationships.
- It is ideal for processing transactions, because of its constraining nature. Therefore, making this structure more efficient for input constraints and locking them.
- Relational databases are the most popular query tool across businesses. The tabular structure makes them a good choice for records with uncomplicated relationships.
For example, Because simple data with known relationships fits neatly into the relational database structure, relational databases are useful for accounting and other transactional data. But this will get complex and rigid when we have complicated relationships.
“When trying to find patterns or insights within data, graphs are much simpler than relational.”
For example in MySQL we have :
And yes, now we can talk about graphs!
Most detective movies have some sort of “evidence board”. Pins of victims, witnesses, suspects all fixed carefully on the board, connecting dots, figuring out the pattern, and thoroughly analyzing before concluding. Immediately you can see the power of connecting the dots in all of those relationships.
Well, this simply sums up the graph database. It’s made of nodes that have labels and properties. And these nodes in turn are connected by relationships.
So it’s simply dots and lines. And it’s easier in many aspects, which is interesting since complicated systems break more frequently. It’s also more effective, especially when the interpretation is discovered via data relationships.
Now, direct relationships are pretty simple to do in relational tables. But when it comes to indirect relationships, it is not so easy. Countless joins are required to achieve indirect relations in relational tables. However, this is difficult and time-consuming, especially if you’re trying to answer queries that you couldn’t have foreseen while creating the schema. As a result, the rigidity.
So the Relational database works great with known questions. But it could be very hard to answer unknown questions.
Now with a graph DB, you can answer unknown questions too. You don’t need to know the query you are answering if you have all the data and the paths connecting them.
You may also add additional relations while maintaining performance.
However, this might lead to assumed relationships that aren’t truly meaningful. As a result, graph databases can be an incredible place to start a query, but they aren’t always the best place to get answers. As a result, searches that are immediate in a relational model, take a long time in graphs. If you’re not cautious, it may soon get complicated. There also isn’t a common query language, thus it is totally platform-dependent.
- The increased emphasis on relationships in graph databases aids in the exploration of large data sets. It benefits data professionals in discovering unexpected connections between data points, making them an excellent solution for use cases involving relationships.
- Social networking, fraud detection, and recommendation engines are all common use cases for graph databases.
- The ability to map relationships makes graph databases a good fit for data visualization.
Organizations may also benefit from using both types of databases. They cater to different needs. Both prioritize connections, but how those relationships are structured gives advantages or disadvantages for different applications.
Just like how movies have a SQL for better understanding, we too have one 😉