开发者

Graph database to return a list of common friends among 2 person in a social network

开发者 https://www.devze.com 2023-04-01 11:48 出处:网络
Are there any graph database(s) that has a built-in feature to return a list of common friends among 2 or more people - just like in a social network like Facebook? The result should be returned as fa

Are there any graph database(s) that has a built-in feature to return a list of common friends among 2 or more people - just like in a social network like Facebook? The result should be returned as fast as possible without the need to perform complex calculations or to traverse the database. If not, what are th开发者_如何转开发e ways to implement it? What about OriendDB? What about using a combination of graph database and Redis?


Not sure about specific graph databases (I come at this from building my own graph database on top of redis) but assuming that friend means a direct connection, finding common friends is fairly simple - just get the full friends list from each and calculate the intersection.

Redis has a command to do this natively and very fast. The SQL query for it is also fairly simple. Getting all connections for a single node should be available on any graph database, and even if you need to retrieve the full lists and calculate the intersection in app code, performance will probably be adequate as long as you don't have to deal with people who have thousands/millions of friends.

Where it gets more complex is dealing with indirect relationships - the intersection operation is the same, but the sets don't exist in the form needed without traversing the graph, so before calculating the intersection you need to build a set of all second level connections for each user. You can either do this as the first step of your query or maintain permanent sets updated when connections change - the appropriate method depends on whether you need to optimize for data usage and write performance or read performance.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号