users able to share tweets
users can subscribe to other users
users can favorite tweets
tweets can include both media files and texts
users receive notifications when people they subscribe post tweets
support user worldwide
high scalability, reliability for a big scale
low latency
100 million users, 10% DAU -> 10 million
10 million tweets created per day -> 100 write qps, ~ 200 peak qps
Suppose on average users check tweets 10 times per day -> 1k read qps to retrieve tweets from users they subscribe.
one char 1 byte, ~300B, let's assume on average 100B, and 10% of tweets have media, with average 3MB -> 1GB text, 1TB media every day ->~400GB text, ~400TB media per year
REST APIs
request {
long requestUserId
// for pagination
long anchorId
int limit
boolean isFavorite
}
response {
list
long nextAnchorId
}
struct Tweet {
long id
String text
List
}
request {
long requestUserId
long followingUserId
// enum action, can be follow or unfollow
Action action
}
response {
boolean successful
// error messages if not successful. Used by clients to deliver user-facing messages
Set
}
request {
long requestUserId
String text
List
}
response {
boolean successful
// error messages if not successful. Used by clients to deliver user-facing messages. examples like reaching daily limit
Set
long tweetId
}
request {
long requestUserId
long tweetId
}
response {
boolean successful
// error messages if not successful. Used by clients to deliver user-facing messages.
Set
}
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...
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...
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...
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?