Baozi Training System design interview: how to design a simple twitter search system

Posted baozitraining

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Baozi Training System design interview: how to design a simple twitter search system相关的知识,希望对你有一定的参考价值。

Methodology: READ MF!

[Originally from the Post: System design interview: how to design a chat system (e.g., Facebook Messenger, WeChat or WhatsApp)]


Remind ourselves with the "READ MF!" methodology.

Requirements

Simple text based search with "AND" or "OR" support. E.g., give me all the tweets that have words "Black" AND "Life" in it sorted by published time in descending order.

 search(api_dev_key, search_terms, maximum_results_to_return, sort, page_token) 

A follow up question would be sort those results in other orders, E.g., give me all the tweets that have words "Black" AND "Life" in it sorted by the most commented tweets in descending order.

Estimation

  • Storage: assuming twitter has 1B users, 50% of them post a tweet per day, each tweet is 140 char = 280Byte. Each day, 1B * 0.5 * 280(roughly 300)Byte = 150GB data
  • Write QPS = 1B user * 0.5 post a tweet per day / 86400 = 5787 QPS = 6000 QPS
  • Query QPS = assuming 3x than write QPS = 18000 QPS
Write QPS in general we don‘t worry too much since it could be processed asynchronously. 18000 QPS for read is easy to handle as long as we have enough number of boxes and most of query would be returned via memory (not hitting disk). 
 

Key designs and terms

技术图片
 
You can also divided the system as usual into three major layers, presentation, service and data layer.

A few key terminologies.

If the follow up question, we just need to build another index given the sort key or we could fetch the results on flight and sort (local optimal). Follow "Index -> Search -> Rank" steps.

  Baozi Youtube Video


References (Credits to original authors)

以上是关于Baozi Training System design interview: how to design a simple twitter search system的主要内容,如果未能解决你的问题,请参考以下文章

Baozi Leetcode solution 135: Candy

Check-N-Run: a Checkpointing System for Training Deep Learning Recommendation Models | NSDI‘ 22

Baozi Leetcode solution 169: Major Element

Baozi Leetcode solution 72. Edit Distance

Baozi Leetcode solution 54: Sprial Matrix

Baozi Leetcode solution 229: Major Element II