create account

The use of graphs in databases: Advantages and options by gwajnberg

View this thread on: hive.blogpeakd.comecency.com
· @gwajnberg ·
$22.58
The use of graphs in databases: Advantages and options
![](https://images.ecency.com/DQmRjU43igdHb2i6WA4mYLU4nugx7NGreCwoojqcCZ7YGfH/copy_of_copy_of_copy_of_banner_pizza_news_2_.png)


<div class = "text-justify">
<p>&emsp; I learned about databases (DB) during a specific course in my graduate program. I am talking about the year 2011 or 2012, I need to check the transcript to be more exact. At that time the consensus of using databases was very clear. The more traditional option of course that I learned was the Structured Query Language or SQL, also known as relational databases. There I learned how to design a good database schema, for those not aware about it, a database schema is nothing more about the skeleton of the DB, such as how many and what tables we will have in there, how they are connected between each other using relations. Also, I learned how to feed the database with data and how to query after the database is populated. Mostly the option that we used in the course was PostgreSQL, but there are also other options such as MySQL. </p>

<p>&emsp; During my whole career until now I have been using SQL to solve my DB problems, until the beginning of the year. In my new job, my supervisor presented a new type of database structure using graphs. Just a little bit of context, graphs are a way to represent things and how they are connected with each of these things. The first usage of a graph was performed by the mathematician Leonhard Euler in the 18th century to solve the problem of bridges in the city of Königsberg. He reduced the city into a draw of vertices (each region of the city) and edges (each bridge that should be constructed). That way to represent relationships is very used in biology, and more in molecular biology to represent the interaction between genes for example.Bellow you can see a figure of gene interactions network using graphs in a figure from the first paper that I published <a href="https://pubmed.ncbi.nlm.nih.gov/26185765/">(Wajnberg et al., 2015).</a></p>

![](https://images.ecency.com/DQmYVfJa7uMjVEmU8Bhno4muzTakrWUb2vKadms8uk2pcR1/image.png)

<p>&emsp; GraphQL the first graph database solution was developed by facebook in 2012, interesting that I was learning about SQL databases at that time, however it was open-sourced only in 2015. So basically people started to use more after 2015. What are the advantages? So let's talk about what are the difficulties that SQL language can bring. First in the schema: To connect two or more tables we will need to add extra columns in them that will help them to connect to each other, such as those called primary keys, which are unique Id's for each row, in addition to that we need foreign keys as the example bellow:

![](https://images.ecency.com/DQmeW3cuyqYsavt9gjEorgLc3CnEmQeXVMM9J1sDcCduiMx/image.png)
*diagram created at app.diagrams.net*

<p>&emsp; For the tables to be connected they are using the primary keys from the previous table as a foreign key, so we need to be cautions when we create the table to add this foreign keys. In the case of graphql is more fluid! We don't need foreign keys, and many times even we don't need to add schema previously. We just use JSON files with indentation separating the relationship, like the example below using the same entities from the SQL example:  </p>

![](https://images.ecency.com/DQmUejHxk5UdFhnUmfshE4TyL3d49XxF5By7oL1dftCguLb/image.png)



*JSON format of the same schema  from the SQL example, real data removed to privacy protection*

![](https://images.ecency.com/DQmerYL5BPjKQueiw7qc1m8r3YDR9cVMBwGJxUfQas816wT/image.png)
*graph representation of the data, with names erased*



<p>&emsp; In addition to the schema design, the insert of data is also simpler, while in SQL we still need to keep in mind to always link which Sample_id will be in the next table, and which food_id will be in the next table, using graphs you don't need to worry with that, so it is less headaches. And the something happens to the query where in SQL we will need to INNER JOIN tables, while using graphs the query is simpler with less just mentioning which vertices names we want to see in the result in a certain query. </p>

## Graph database options

DGRAPH
![](https://images.ecency.com/DQmTZbHJRfxPvGuVtDmxVEB5Vu3EkiVwwDPEi2zudSC7iNB/image.png)
*print screen from dgraph webpage*

<p>&emsp; DGraph uses graphQL syntax and also their own syntax called DQL, which has more shortcuts. However, for some reason DQL didn't become so popular, so most of the people who uses Dgraph nowadays only use graphQL syntax. You can check it out more in <a href="https://dgraph.io/">here </a>. They have a cloud instance which is paid, like any other cloud instance. But it is free to run in any computer or server. There are clients for python and nodeJS of course. </p>

CosmoDB+gremlin API
![](https://images.ecency.com/DQmUua6FeRU6LkqvZ21fzwYvVkThokscW6zCbsjcAcw6drx/image.png)



*print screen of my azure portal login*

<p>&emsp; Microsoft of course invested a bit into graphql, and using the Gremlin syntax, added this available in their Azure portal, a interesting option to build your database using graphs. Gremlin syntax is a bit different because it doesn't use JSON format, it has something similar to a command line instead for data insertion and queries.


Other Options
<p>&emsp; There are other options such Neo4J or implementing GraphQL syntax in your own script for example in this amazing tutorial by The Net Ninja, which I recommend all his tutorials, I learned to react app with his tutorials. Bellow you can find the initial introduction of a free course that he shows how to integrate GraphQL and a react app. </p>
https://www.youtube.com/watch?v=Y0lDGjwRYKw&list=PL4cUxeGkcC9iK6Qhn-QLcXCXPQUov1U7f

## Conclusion
<p>&emsp; Graphs are an interesting way to implement your database, and it is worth taking a look at, big companies with big data are using it, so it is worth giving a look and a chance. I hope that this article opens the eyes of people willing to learn more about it. Like I read once in here, devs should be in continuing education and updating all the time.</p>

![](https://images.ecency.com/DQmbniAPLZJ4yJsiNn4UMyZjRX1scfGyDNrVCiyy1Ytrj1n/copy_of_copy_of_copy_of_by_rantree.png)








</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 571 others
👎  , , ,
properties (23)
authorgwajnberg
permlinkthe-use-of-graphs-in
categoryhive-169321
json_metadata{"links":["https://pubmed.ncbi.nlm.nih.gov/26185765/","https://dgraph.io/","https://www.youtube.com/watch?v=Y0lDGjwRYKw&list=PL4cUxeGkcC9iK6Qhn-QLcXCXPQUov1U7f"],"image":["https://images.ecency.com/DQmRjU43igdHb2i6WA4mYLU4nugx7NGreCwoojqcCZ7YGfH/copy_of_copy_of_copy_of_banner_pizza_news_2_.png","https://images.ecency.com/DQmYVfJa7uMjVEmU8Bhno4muzTakrWUb2vKadms8uk2pcR1/image.png","https://images.ecency.com/DQmeW3cuyqYsavt9gjEorgLc3CnEmQeXVMM9J1sDcCduiMx/image.png","https://images.ecency.com/DQmUejHxk5UdFhnUmfshE4TyL3d49XxF5By7oL1dftCguLb/image.png","https://images.ecency.com/DQmerYL5BPjKQueiw7qc1m8r3YDR9cVMBwGJxUfQas816wT/image.png","https://images.ecency.com/DQmTZbHJRfxPvGuVtDmxVEB5Vu3EkiVwwDPEi2zudSC7iNB/image.png","https://images.ecency.com/DQmUua6FeRU6LkqvZ21fzwYvVkThokscW6zCbsjcAcw6drx/image.png","https://images.ecency.com/DQmbniAPLZJ4yJsiNn4UMyZjRX1scfGyDNrVCiyy1Ytrj1n/copy_of_copy_of_copy_of_by_rantree.png"],"thumbnails":["https://images.ecency.com/DQmRjU43igdHb2i6WA4mYLU4nugx7NGreCwoojqcCZ7YGfH/copy_of_copy_of_copy_of_banner_pizza_news_2_.png","https://images.ecency.com/DQmYVfJa7uMjVEmU8Bhno4muzTakrWUb2vKadms8uk2pcR1/image.png","https://images.ecency.com/DQmeW3cuyqYsavt9gjEorgLc3CnEmQeXVMM9J1sDcCduiMx/image.png","https://images.ecency.com/DQmUejHxk5UdFhnUmfshE4TyL3d49XxF5By7oL1dftCguLb/image.png","https://images.ecency.com/DQmerYL5BPjKQueiw7qc1m8r3YDR9cVMBwGJxUfQas816wT/image.png","https://images.ecency.com/DQmTZbHJRfxPvGuVtDmxVEB5Vu3EkiVwwDPEi2zudSC7iNB/image.png","https://images.ecency.com/DQmUua6FeRU6LkqvZ21fzwYvVkThokscW6zCbsjcAcw6drx/image.png","https://images.ecency.com/DQmbniAPLZJ4yJsiNn4UMyZjRX1scfGyDNrVCiyy1Ytrj1n/copy_of_copy_of_copy_of_by_rantree.png"],"tags":["hive-169321","stem","stemsocial","hive-engine","database","neoxian","proofofbrain","archon","graphql","science"],"description":"","app":"ecency/3.0.29-vision","format":"markdown+html"}
created2022-12-01 22:57:39
last_update2022-12-01 22:57:39
depth0
children6
last_payout2022-12-08 22:57:39
cashout_time1969-12-31 23:59:59
total_payout_value11.344 HBD
curator_payout_value11.235 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,236
author_reputation150,336,851,968,122
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,773,581
net_rshares47,001,470,314,216
author_curate_reward""
vote details (639)
@arcange ·
Dear @gwajnberg,<br>Your support for the current HiveSQL proposal (#138) is much appreciated but the proposal will expire soon!<br>May I ask you to review and support the new proposal so HiveSQL can stay free to use for the community?<br>You can support the new proposal (#247) on [Peakd](https://peakd.com/me/proposals/247), [Ecency](https://ecency.com/proposals/247), [Hive.blog](https://wallet.hive.blog/proposals) or [using HiveSigner](https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22247%22%5D&approve=true).<br><br>Thank you!
properties (22)
authorarcange
permlinknotify-gwajnberg-20221205021523
categoryhive-169321
json_metadata""
created2022-12-05 02:15:24
last_update2022-12-05 02:15:24
depth1
children0
last_payout2022-12-12 02:15:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length551
author_reputation1,065,065,779,136,773
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,856,919
net_rshares0
@hivebuzz ·
<table><tr><td><a href="https://hivebuzz.me/@gwajnberg"><img src="https://images.hive.blog/70x70/https://hivebuzz.me/badges/wc2022/wc2022-43.s1.png"></a></td><td>Well done @gwajnberg! You successfully guessed the match result and unlocked your badge!<br><sub>Click on the badge to view your board. Click [here](https://hivebuzz.me/rankingWC) to check your ranking.</sub></td></tr></table>

Thank you to our sponsors. Please consider supporting them.
|||||
|-|-|-|-|
|![](https://images.hive.blog/32x32/https://images.hive.blog/u/arcange/avatar) **@arcange**|![](https://images.hive.blog/32x32/https://images.hive.blog/u/leofinance/avatar) **@leofinance**|![](https://images.hive.blog/32x32/https://i.imgur.com/Zhlrijh.png) **@threespeak**|![](https://images.hive.blog/32x32/https://i.imgur.com/fNLIiXE.png) **@wrestorgonline**|

**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202211-result"><img src="https://images.hive.blog/64x128/https://i.imgur.com/mzwqdSL.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202211-result">Hive Power Up Month Challenge 2022-11 - Winners List</a></td></tr><tr><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day11"><img src="https://images.hive.blog/64x128/https://i.imgur.com/uNPMgnd.png"></a></td><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day11">HiveBuzz World Cup Contest - Recap of Day 11</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pum-202212"><img src="https://images.hive.blog/64x128/https://i.imgur.com/M9RD8KS.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202212">Be ready for the last Hive Power Up Month of the year!</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-gwajnberg-20221201t234038
categoryhive-169321
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-12-01 23:40:39
last_update2022-12-01 23:40:39
depth1
children0
last_payout2022-12-08 23:40:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,662
author_reputation367,970,851,016,021
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,774,608
net_rshares0
@hivebuzz ·
<table><tr><td><a href="https://hivebuzz.me/@gwajnberg"><img src="https://images.hive.blog/70x70/https://hivebuzz.me/badges/wc2022/wc2022-49.s1.png"></a></td><td>Well done @gwajnberg! You successfully guessed the match result and unlocked your badge!<br><sub>Click on the badge to view your board. Click [here](https://hivebuzz.me/rankingWC) to check your ranking.</sub></td></tr></table>

Thank you to our sponsors. Please consider supporting them.
|||||
|-|-|-|-|
|![](https://images.hive.blog/32x32/https://images.hive.blog/u/arcange/avatar) **@arcange**|![](https://images.hive.blog/32x32/https://images.hive.blog/u/leofinance/avatar) **@leofinance**|![](https://images.hive.blog/32x32/https://i.imgur.com/Zhlrijh.png) **@threespeak**|![](https://images.hive.blog/32x32/https://i.imgur.com/fNLIiXE.png) **@wrestorgonline**|

**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202211-delegations"><img src="https://images.hive.blog/64x128/https://i.imgur.com/fg8QnBc.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202211-delegations">Our Hive Power Delegations to the November PUM Winners </a></td></tr><tr><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day13"><img src="https://images.hive.blog/64x128/https://i.imgur.com/uNPMgnd.png"></a></td><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day13">HiveBuzz World Cup Contest - Recap of the last day of the group stage.</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pud-202212-feedback"><img src="https://images.hive.blog/64x128/https://i.imgur.com/zHjYI1k.jpg"></a></td><td><a href="/hive-122221/@hivebuzz/pud-202212-feedback">Feedback from the December Hive Power Up Day</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-gwajnberg-20221203t183842
categoryhive-169321
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-12-03 18:38:42
last_update2022-12-03 18:38:42
depth1
children0
last_payout2022-12-10 18:38:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,709
author_reputation367,970,851,016,021
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,822,898
net_rshares0
@hivebuzz ·
<table><tr><td><a href="https://hivebuzz.me/@gwajnberg"><img src="https://images.hive.blog/70x70/https://hivebuzz.me/badges/wc2022/wc2022-51.s1.png"></a></td><td>Well done @gwajnberg! You successfully guessed the match result and unlocked your badge!<br><sub>Click on the badge to view your board. Click [here](https://hivebuzz.me/rankingWC) to check your ranking.</sub></td></tr></table>

Thank you to our sponsors. Please consider supporting them.
|||||
|-|-|-|-|
|![](https://images.hive.blog/32x32/https://images.hive.blog/u/arcange/avatar) **@arcange**|![](https://images.hive.blog/32x32/https://images.hive.blog/u/leofinance/avatar) **@leofinance**|![](https://images.hive.blog/32x32/https://i.imgur.com/Zhlrijh.png) **@threespeak**|![](https://images.hive.blog/32x32/https://i.imgur.com/fNLIiXE.png) **@wrestorgonline**|

**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-102201/@hivebuzz/wc2022-recap-r16-day1"><img src="https://images.hive.blog/64x128/https://i.imgur.com/uNPMgnd.png"></a></td><td><a href="/hive-102201/@hivebuzz/wc2022-recap-r16-day1">HiveBuzz World Cup Contest - Round of 16 - Recap of Day 1</a></td></tr><tr><td><a href="/hive-122221/@hivebuzz/pum-202211-delegations"><img src="https://images.hive.blog/64x128/https://i.imgur.com/fg8QnBc.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202211-delegations">Our Hive Power Delegations to the November PUM Winners </a></td></tr><tr><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day13"><img src="https://images.hive.blog/64x128/https://i.imgur.com/uNPMgnd.png"></a></td><td><a href="/hive-102201/@hivebuzz/wc2022-recap-day13">HiveBuzz World Cup Contest - Recap of the last day of the group stage.</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-gwajnberg-20221204t173257
categoryhive-169321
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-12-04 17:32:57
last_update2022-12-04 17:32:57
depth1
children0
last_payout2022-12-11 17:32:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,726
author_reputation367,970,851,016,021
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,845,465
net_rshares0
@poshtoken ·
https://twitter.com/1451373011018338304/status/1598451629417811974
<sub> The rewards earned on this comment will go directly to the people( @gwajnberg ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
👍  
properties (23)
authorposhtoken
permlinkre-gwajnberg-the-use-of-graphs-in-1595
categoryhive-169321
json_metadata"{"app":"Poshtoken 0.0.1","payoutToUser":["gwajnberg"]}"
created2022-12-01 22:59:12
last_update2022-12-01 22:59:12
depth1
children0
last_payout2022-12-08 22:59:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length268
author_reputation3,941,853,334,775,549
root_title"The use of graphs in databases: Advantages and options"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id118,773,616
net_rshares25,182,797,552
author_curate_reward""
vote details (1)
@stemsocial ·
re-gwajnberg-the-use-of-graphs-in-20221202t221035776z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-gwajnberg-the-use-of-graphs-in-20221202t221035776z
categoryhive-169321
json_metadata{"app":"STEMsocial"}
created2022-12-02 22:10:36
last_update2022-12-02 22:10:36
depth1
children0
last_payout2022-12-09 22:10:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,460,334,324,555
root_title"The use of graphs in databases: Advantages and options"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id118,801,435
net_rshares0