System requirements

Objects

  1. Account
  2. Tweet

Functional:

  1. User should be able to tweet a message
  2. User should be able to like a tweet
  3. User should be able to get his tweets
  4. User should be able to get his feed
  5. A tweet can contain a another tweet(Retweet)



Non-Functional:

  1. Performance
  2. Availabilty
  3. Consistency
  4. Scalable




Capacity estimation

Assume we have 100M Total users, out of whih 20% are DAU which is 20M.


User Account can have details like:

UserID(20B)

User Name(20B)

Location(20B) other details can include .. total may be 100Bytes


so total accounts data can be : 100M * 100Bytes = 10GB ~ 40GB(lets assume we grow to 4x in next 2 years)


and each user on an avg can tweet 5 tweets and each tweet of 150 chars : each tweet 200B -> 5 tweets -> 1KB


20M active users -> 20M * 1000B -> 20*1000*MB -> 20GB per day

for 1 year -> 20*500GB --> 10000GB->10TB in year ~ 20TB with growth


Write TPS --> 20M*5 = 100M/100K ~ 1000TPS ~ 5K tps


Read TPS -> assume each user wants top 40 tweets --> then 40K TPS








API design

/getTweets/userid/{userid} O/P: tweets by the user

/getFeed/userid/{userid} O/p : tweets from followers

/likeTweet/tweetId/{tweetid}






Database design

Accounts:

account_id

Name

location

joined_date

active_at


Tweets:

tweet_id

author_id

tweet

created_at


Followers:

account_id

follower_id

status




High-level design

You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...







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?