System requirements


Functional:

  1. I want to post a tweet
  2. I want to reply to tweets
  3. React
  4. I want to retweet
  5. I want to follow some people
  6. I want to view top 10 most popular tweets from people I'm following, scroll down to view 10 more tweets at a time
  7. I want to view tweets from a person on their profile
  8. I want to add hashtags
  9. I want to click on a hashtag and get the most popular tweets


Non-Functional:

  1. Highly available
  2. Eventually consistent - delay in viewing tweets is ok, popularity and hashtags can be approximate. Replies must be ordered.
  3. Durable
  4. Latency under 200ms for viewing feed or profile
  5. Secure login experience



Capacity estimation

  1. Scale up to 1B global users, 10k tweets per second
  2. Celebrity - upto 100M followers, average person - 1000 followers and followed by.
  3. 1KB per tweet, 1TB per day for tweets
  4. Follower, profile etc 10GB
  5. 100k hashtags





API design


Login API


POST /users


response {userId}


Profile API

GET /profile/


Response {"", tweets: ["",""], nextP }

Tweet CRUDL

POST /tweets, GET...


params: userID

body {


text

list of hashtags

}


reply CRUDL

POST /tweets//reply

params: userId


body{

text

list of hashtags

}


REact crudl


tweetid

emojiId



follow API

POST /followers/


GET /feed







Database design

Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...






High-level design







Request flows

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...






Detailed component design

Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...






Trade offs/Tech choices

Explain any trade offs you have made and why you made certain tech choices...






Failure scenarios/bottlenecks

Try to discuss as many failure scenarios/bottlenecks as possible.






Future improvements

What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?