Friendship Service
好友关系的存储与查询
单向好友关系
双向好友关系 单向好友关系
例子:Twitter、Instagram、微博
存在 SQL 数据库时
查询x所有的关注对象:
select * from friendship where from_user_id=x
查询x所有的粉丝:
select * from friendship where to_user_id=x
存在 NoSQL 数据库时
双向好友关系 例子:微信,Facebook,WhatsApp 方案1:存储为一条数据
select * from friendship where smaller_user_id = x or bigger_user_id=x
问:为什么需要区分 smaller / bigger?
SQL 可以按照这种方案
NoSQL 很多不支持 Multi-index 不能使用这种方案 方案2:存储为两条数据
select * from friendship where from_user_id=x
NoSQL 和 SQL 都可以按照这种方案