System Design Divide and Conquer, use Twitter Design as an example

Interview Question: Design Twitter

before you answer this problem, you need to know what can counted as a “good answer”.
work solution(it must be workable)
special case: answer the question based on the different properties of the system we are about to design.
analysis: show them the process of analysis
trade off: it’s a part of analysis technically.
knowledge base: you need to know enough terms or techniques to solve this problem

the most important part for above five parts are Analysis. so how to analysis following a general guideline?

  1. scenario: asking clearly about the following attributes of the system we are about to design: what features do we need to have? what QPS for the server to handle? and what’s the approximate DAU?
  2. services: split the big system into specific smaller services.
  3. storage: how to storage and access those data: SQL or NoSQL? what’s the file system should looks like?
  4. scale: thinking about the future: how to handle possible problems when the DAU surge in a short time? how to handle the special cases? how to optimize the system?

Use Twitter design as an example:
first S:
first part, about the functions of this app: what are the functions needs to be implemented? tweet/re-tweet, follow/unfollow, like/unlike, comment, search for tweets/users, looking for the personal page of current user and other users. how to manage feeds timeline? what is the difference for registered user and visitors?(just think about all the workflows of cozyou app)
second part is about the user we need to handle: about the number of visits we need to handle? what’s the daily active user? what’s the monthly active user.
Then we choose the core functions we need to implement, because we only have limit times.
so the core functions for an app like twitter, are: login/register, post, timeline, news feed, follow/unfollow.
choose the core user-related perporties: concurrent user(DAU * number of requests per user / number of seconds per day), peak number of request. Read QPS(300K for twitter)/ Write QPS(5K for twitter)

Second S:
Divide:
Merge: merge the service with similar target
and finally, we have: user service{register/login}, tweet service(post, personal news feed, timeline), media service(photos and videos), friendship service:(follow/unfollow)

Third S:
first, choose from SQL/NoSQL, and file system. (and we choose them for every service instead of app)
then, make a detailed structure of tables.
程序==算法+数据结构
系统= = 服务 +储存
在这里插入图片描述
Fourth S:
Scale contains two parts: Optimize and Maintenance.
Part1 optimize: 解决设计缺陷(pull model or push model? normalize or de-normalize),增加更多功能(edit, ads),增加特殊用例(users like Donald Trump, Lebron James, or Zombie users)
Part2:Maintenance: 系统的强健性(有一台服务器或者数据库挂了怎么办)/系统的可拓展性(如果流量暴增 该如何拓展)

posted @ 2020-10-23 04:49  EvanMeetTheWorld  阅读(20)  评论(0)    收藏  举报