500M DAU, assume each posts 1 tweet, search 30 tweets daily.
Write
500M/10^5 = 5000 TPS
Read
500M * 30 / 10^5 = 150k TPS
Storage
500M * 1KB * 365 = 1.82PB/year
Tweet
Partition key: user_id + location for the following reasons:
Choose NoSQL given the huge amount of storage we need. Also we don't need strict consistency in this use case. NoSQL can provide better read/write performance.
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
We will have two main service, app server and the search service. The former handles tweets creation, and forward all search requests to search service.
When a tweet is created, app server inserts it into the databse/cach, then puts the id to message queue. An index service will pull it from the queue, creates reverse index (index to document), and inserts into elastic search for future search query.
When a search request comes, search serivce first check if the request is stored in cache, if not, it invokes elasticsearch to get the results.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?