Create Tweet
View Tweets - sorted chronologically OR relevance/popularity
Favorite Tweets
Follow Users
Search Tweets - keywords or hashtags
Filter/Sort - by media type
Large number of viewers
First 10 tweets show within 500ms
Eventual consistency OK
500 million DAU X 100 tweets viewed a day = 50 billion reads
500 mil DAU x 2 tweets written a day = 1 billion writes
Peak usage: 20% of users (100 million simultaneous read/writes)
POST /v1/tweet/ Parameters: post_text, has_complex_content, auth_token
GET /v1/feed/ Parameters: auth_token, page_number, start_timestamp, end_timestamp (optional)
POST /v1/follow/id: auth_token
DELETE /v1/follow/id: auth_token
POST /v1/tweet/id/retweet: auth_token
POST /v1/tweet/id/favorite: auth_token
Users:
Follows:
Posts:
Favorites:
Hashtags:
HashtagPosts:
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...
Create Tweet:
Feed Generator:
Get News Feed:
Follow/Unfollow:
Favorite/Unfavorite:
User cache: uses user ID as key and shards on that
Newsfeed cache:
New Post Queue:
Meta Cache:
Local Cache:
Post Tweet failure: If the standard flow fails, an HTTP Error code is returned, which shows to the user in the client. If there is complex content (image/videos), if the Image / Video processing job fails explicitly, it sends a notification which will show to the user when notifications are fetched, and the post and content are removed. There can also be an occasional job that checks for too much time between initial post storage time and now, and if that has occurred, send a notification to the user and delete the content.
Get Feed failure: On error, return HTTP error code. If CDN is down, user can fetch directly from S3.
Hot Key problems: A user with a lot of followers could create a lot of traffic for the Feed Generator when they post. We could treat these users differently and have a separate infrastructure for fetching those posts (separate from other posts) instead of having them proactively pushed to the Feed Generator. We can flag these users so their posts aren't processed by Feed Generator, and
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?