Efficient way to implement LinkedIn like “How you are connected to” feature?

前端 未结 2 1230
Happy的楠姐
Happy的楠姐 2021-01-31 23:06

LinkedIn has this cool feature in which while visiting some user\'s profile, LinkedIn prompts how you are connecting to that user through the network.

Assuming that the

2条回答
  •  忘掉有多难
    2021-01-31 23:46

    You can see how this can be done in the article Graphs in the database: SQL meets social networks by Lorenzo Alberton. The example code is written for PostgreSQL using CTEs. However, I doubt that using a RDBMS for this will perform well. I wrote up an article on how to do the same stuff as in the mentioned article using a native graph database, in this case Neo4j: Social networks in the database: using a graph database. Other than the differences in performance, a graph database also simplifies the task by providing a graph API that makes it easy to handle traversals that would be extremely complex to write in SQL (or by using stored procedures). I wrote a bit more on graph databases in this thread and see this one too.

提交回复
热议问题