graph-databasesbidirectional-relation

Why don't most graph databases support bidirectional edges?


I have to choose a graph database system and am very surprised that the mainstream ones don't support this feature ?

Why is it such a no-go for database systems ? And why developers out there don't seem to ask for it ? There should be a reason I'm not aware of.

Thanks for your help.


Solution

  • To my understanding, a "pure" bidirectional graph database cannot support cases where there are also unidirectional relationship, Twitter for example.

    So the question becomes "why there are no hybrid (bidirectional and unidirectional) graph databases?" There are two problems with this solution:

    1. It might not save storage as you expected because for bidirectional relationship, a hybrid graph database would need to store three edges instead of just one: A -> B, B -> A, and A <-> B. The reason is that some very common queries involve unidirectional relationship.

    2. The cost of some basic queries is rather high. For example, there are two frequently asked questions in graph databases:

      • Find all friends of A

      • Find all friends of B

    Commonly a graph database saves all friends of A as edges adjacent (AB, AC, AD, …). To find all of A's friends they just need to locate A and skim to the first edge whose prefix is not A. Suppose A has m friends and there are n. records in database in total, then the query complexity is O(log(n)) + O(m). The same logic applies to B. However, in case bidirectional edge is used, say A<->B, the cost of query for A's friends is the same but query for B's friends would be O(n) because a full database scan is required.