Twitter

作者: Michelle_G | 来源:发表于2021-10-05 11:53 被阅读0次

github:

https://github.com/donnemartin/system-design-primer/blob/master/solutions/system_design/twitter/README.md

video:

https://www.youtube.com/watch?v=KmAyPUv9gOY&feature=emb_title

3个feature

1.tweeting

2.timeline user+home

3.following

发状态

naive solution

用relational database 

如mysql 存在两张表中,但是这样性能太差 在build home timeline的时候

solution 1

在memory cache 这里用的redis 中提前存所有user的homeline 每当有user 发状态,这个user的所有follower(从follower表中找)的home timeline就会更新,根据follower表,知道她有哪些粉丝,然后在redis中更新这些粉丝的timeline。

redis是三副本,因此如果alice有100个粉丝,那么就会有300个home timeline更新

但是这个还是有问题,如果一个明星发了状态,就会有很多个timeline需要更新,因此

实际上 twitter做了特殊处理,对于celebrity的状态,不会更新redis中 ta的粉丝的timeline,而是每次粉丝打开timeline时,看这个粉丝follow了哪些celebrity 然后找这些celebrity的状态,和redis中的timeline merge(按照时间顺序)

(github)We could also avoid fanning out tweets from highly-followed users. Instead, we could search to find tweets for highly-followed users, merge the search results with the user's home timeline results, then re-order the tweets at serve time.

看状态

https://www.infoq.com/presentations/Twitter-Timeline-Scalability/


相关文章

网友评论

      本文标题:Twitter

      本文链接:https://www.haomeiwen.com/subject/owgoqktx.html