DEV Community

Cover image for When To Use Graph Database Model Over Relational Database Models
Ahmed Hisham
Ahmed Hisham

Posted on

When To Use Graph Database Model Over Relational Database Models

There are a lot of different database models out there. Nothing is right and wrong, it all depends on the cases and the requirements of the project, the blog will focus on when to use Graph databases over relational ones.

When to use a Graph model?

  1. When Complex relations exist between data. A general and common case is when building a social media app, you will most probably use a Graph model to handle relations between users, as graph model will be much easier structure to handle complex interconnected data.

  2. When project data model is inconsistent and requires frequent changes. Given social media app as an example, the shape of data will often be changed as demands and requirements change, so having flexible data model is necessary

  3. When Additional attributes are only necessary for some entities (not all of them), in these cases working with relational databases will force you to create a separate table (best practices) to handle additional attributes rather than having (null) value for those attributes in rows that don't have values for them, so it's harder to handle those type of issues in relational models than in graph models which is simpler, and changing the data structure at any point in time is easier

  4. Running reading queries is simpler with cypher than sql in a lot of cases

Graph models is not always the best suited, you should always think in terms of performance, which type of databases will bring the best performance possible?, also what type of queries I will often be running?, what kind of data you are working with?, and more importantly what expertise your team has?. Thinking in terms of all of these is important to make the right decision and choose the most suited database model to fit your needs.

I've been using postgres for a quite a long time, and I came recently across an extension that add and power postgres with graph functionalities, the extension is apache/age which is worth checking for those want to leverage both graph and relational databases functionalities in a single database.

Top comments (0)