List the key functional requirements for the system (Ask the AI for hints if stuck)...
Users can post tweets
Users can share tweets with anyone
Users can view and search for tweets
Users can follow other user tweets
Users can add favorite tweets
List the key non-functional requirements (performance, scalability, reliability, etc.)...
I think performance, scalability, reliability, should be there for any system and do not need to be added so its given I will add these
Retry logic for post tweets
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Each user composes 10 tweets a day X 1,00,000 users that 10,000,000 tweets or 416666 per hour with busy times execding that
That is 10,000,000 writes per day
I would say each person reads 100 tweets per day so that is is 100,000,000 reads per day
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
get tweets from seach
GET Twitter/V1/Tweets?search="search term"
RESPONSE
{tweets:[{},{},{}]}
STATUS CODES 200 Even if the seach is empty
get popuar tweet
GET Twitter/V1/Tweets/Hot"
RESPONSE
{tweets:[{},{},{}]}
STATUS CODES 200
post a tweet
POST Twitter/V1/Tweet/
{userToken:"", Tweet:{body:"",timestamp"","tags":[]}}
RESPONSE
{tweetID""}
STATUS CODES 201
share a tweet
GET Twitter/V1/Tweet/Share
REQUEST
{userToken:"", TweetID:123}
RESPONSE
{tweetID"",tweetUrl:}
STATUS CODES 200
Follow a user
POST Twitter/V1/User/Follow
REQUEST
{userToken:"", personToFolowUserToken""}
RESPONSE
{personToFolowUser:ID}
STATUS CODES 200
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
We will the following
Client Web or Mobile
API Gateway
CDN for reading tweets
A get Tweets service
A post Tweets servere
A user user service
A User database :(holds user data)
A tweet database: (holds all static tweet data, body, comments etc)
Tweet Meta database: (holds all non static data about tweets, like like counts, who likes it, who shared it, share count etc)
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Tweets and comments will be stored in a NOSQL database with a indexs on user (the person who created the tweet) and the the comments
each document it would look like this
a tweet
{type: tweet|comment, id:NUM, body, user_id:NUM}
a tweet comment
{type: tweet|comment, id:NUM, body, tweet_id, user_id:NUM}
so there would be a one tweet to many comments
the user database
ID, NOT NULL, NUM
USERNAME, NOT NULL ,CHAR
FOLLOWING, NOT NULL, ARRAY //list of userids
FOLLOWERS, NOT NULL, ARRAY //list of userids
the Tweet Meta database
ID, NOT NULL, NUM
twitter_id NOT NULL, NUM // the ID of the tweet in NOSQL data to get the body etc of the tweet NOT NULL
Like_counts NUM NOT NULL // number of likes
users_that_liked: ARRAY NULL // list of users that liked the tweet
share_list: ARRAY // list of users that shared the tweet
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
There is a strong seperation between posting and getting tweets,on both the server and the data layer
the static tweets are stored in a nosql database for scaling and easy retrival but there is a postgres DB to store user and tweeting meta data.