System requirements
Functional:
- composeTweet: create a tweet
- getTweetForUser: get a tweet feed to track the updates of other users who are followed by a user
- favorTweet: favor a specific tweet
Non-Functional:
List non-functional requirements for the system...
- Availability: 4 9's
- scalability: 400 M total users. 100 M MAU. 34 M DAU
- Security: API token, third party authorization
- Latency: 1s
- Durability: under 5 year for instant access, archive (3 mins access) for more than 5 year
Capacity estimation
Estimate the scale of the system you are going to design...
Peak Hours:
read to write ratio is 1000:1 average
It is a read heavy application: 1B QPS ==> needs to have a good strategy for read
push tweets to normal followers' tweet feeds. pull tweets into tweet feed from celebrities' tweets.
Storage:
lets assume video size per tweet is 100MB other type tweet size is too small and can be ignored. 1:100 tweets is video type 1B/1000 * 0.01 => 1M * 100 MB *0.01 = 1 TB per second. We have around 100000 seconds per day ==> 100 PB per day
Use CDN to store video in the hot zone.
API design
composeTweet(API_token: string, postID: uuid, userid: uuid, metadata: (url of the object/ text) string, mediatype)
request = {API_token: string, postID: uuid, userid: uuid, metadata: (url of the object/ text) string, mediatype}
reponse = {status code: string, postID: uuid, userid: uuid}
getTweetForUser(API_token:string, userid: uuid, pagesize: integer, pageToken: integer)
request = {API_token:string, userid: uuid, pagesize: integer, pageToken: integer}
reponse = {status code: string, metadata: [] {(url of the object/ text) string}: json blob, pageToken: integer}
favorTweet(API_token: string, postID: uuid, userid: uuid)
request = {API_token: string, postID: uuid, userid: uuid}
reponse ={status code: string, postID: uuid, userid: uuid}
Database design
post table: (periodically 5 mins ) indexing by userId
postId: uuid | userId: uuid | metadata: string | mediatype: string | topic: [] {string}| favorUserIds: [] {uuid}
user relationship tables:
userId: uuid | followers: [] {userID: uuid}
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?