System requirements


Functional:

List functional requirements for the system (Ask the chat bot for hints if stuck.)...


  • Users should be able share a tweet
  • Users should be able to follow other users for updates and see their tweets
  • Users should be able to favorite a tweet


Non-Functional:

List non-functional requirements for the system...


  • Eventual consistency is okay because so many users can be tweeting all at once
  • Response time should be miniscule so that a user can read new tweets and make new tweets quickly
  • Scalable
    • Many users should be able to make tweets at the same time


Capacity estimation

Estimate the scale of the system you are going to design...


Suggest we have:

  • 100 DAU
  • A user can make 100 tweets a day
  • A tweet is 140 characters

Estimation:

  • 100*100 = 100,000 tweets a day




API design

Define what APIs are expected from the system...


createTweet({ user_id, content })


refreshTweetFeed({ user_id, recent_tweets})


followUser({ user_id, followed_user_id})


favoriteTweet({ user_id, tweet_id})


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


Tweet_Mapping {

tweet_id,

created_by,

content,

time_created,

likes

}


User_Mapping {

user_id,

followers,

followed,

likes

}



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


  • API Gateway
    • sends requests to proper service
  • Datebase
    • Holds both tweet data and user data
  • CDN
    • cache static contents that are written once and read many times. For example, images and videos posted by a user.


  • Rate Limiter
    • protects all the backend servers from Denial of Service attack, intentional or unintentional.
  • Tweet Service
    • saves tweets to database
  • Home Feed Service
    • constructs a list of tweets to send to user when refreshed
  • Cache
    • show most frequently accessed content




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

  • Tweet is sent through CDN and rate limiter to API gateway to be sent to correct service
    • User creates tweet
    • Tweet Service stores new tweet
  • Users refreshes feeds
    • Home Feed Service checks for most recent content in cache
    • If nothing, check datebase
    • Home Feed Service returns list of tweets to send to user


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


Rate-limiter

  • rates the amount of requests to prevent users from overloading the servers

Home Feed Service

  • when user refreshes page, service will check cache for frequented tweets
  • if no cache, service will check database for recent tweets
  • returns a list of recent tweets



Trade offs/Tech choices

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


For a database, a NoSQL database will work for horizontal scalability.



Failure scenarios/bottlenecks

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


  • Users with many followers sending out a tweet can cause a bottleneck
  • Viral tweets can also cause issues due to high traffic for likes



Future improvements

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


  • adding images and videos
  • locality (language translations)
  • recommending new users to follow