设计微信
Scenario
微信不是点对点通信? 不是,可以留言。历史消息存在服务器,留一段时间(缓冲期)删除,或者不删除。
Service

Storage
Thread table (会话)
有些信息是私有的,未读,静音
方法 1
私有的信息存在 User thread, 如何知道参与人,查找所有表里有相同therad_id, primary key = userId + thread id
弊端:需要跨表查询比较慢
方法 2
实际情况下使用cache , 减少跨表次数。
通过 参与者 查询 thread id

Message 存储结构(写多读少)
Nosql(optimize for write)

Thread SQL

NoSQL
可行解
Scale
实时
Push notification
局限性: 无法支持 Web 端
Socket: 支持 Server push 给客户端
Channel Service 支持群聊
channel service 里的 key 就是 channel 的名字,value 是在这个 channel 下有哪些人。
因为 channel 是一个 key-value 的存储结构,value 是一个 set,支持用户上下线(增删),所以 Redis 是可以很好支持 value 是 set 的一种 key-value 结构。
Q & A

多机登录

用户在线状态显示