user can register and login with their credentials
user can send new friend invite and delete an existing friend
user can send and receive text messages from other friends,
user can send voice message and files to another friends
user can start a call and a facetime to another friends
user can send emoji, picture to other friends, read indicators,
the system should low latency => enough metric to monitoring
the system should support large scaling data
the system should fault tolerance
suppose we have 10million user in total, and say 10% are high active user which is 1 million, and each user send 100 text and each text 100 bytes, 100*100 byte which is 10MB, each user make 1 hour call and 1 hour facetime, for each 1MB can for 3 minutes call, so 1 hour is 20 MB, 200 MB for facetime per hour. we need storage to store voice and text message so each day we need.
in total 1 million *20MB +1million * 10MB
1million * 30MB which is 10*3TB=30TB storage to store text message and voice message. for text message we can store into the database, for files, voice and video files, we can store the actual thing into s3 and put the s3 URL into hte database
//api for user to login with credentials, userInfo is a pojo class //contains user username and password, return true if login succeed, otherwise returnfalse
boolean login(String username, char[] password) throws Exception;
//api for user to register with credentials
//user register with a username, password, email, phonenumber, //geneder, birthday
//return true if login succeed, otherwise returnfalse
boolean register(String username, char[] password, email, phone, gender, birthday) throws Exception;
//api for user to send message
//message: can be text, accachemnt files, voice, video attachment
//return the timestamp when message sendout
long sendMessage(Message message, uuid friend) throws Exception;
//we will create a exception parent class with different child class for different error situation
exeption{
useralreadyexists => 402 //if user email or phone already registered before
wrongcredential => 401//if user enter username doesn't match with password
dependencyerror-> database, s3, => 501 //if any external dependency got error like database, s3,
networkerror->timeout, => 502//if got a connection error, like timeout,
}
//user read a message from a friend, parameter is messageid which is a uuid format, return long which is the timestamp which is the time when read the message
//return the timestamp when read this message
long readMessage(Message message) throws Exception;
//api for user to edit message, return the time stamp when user //edit the message,
long editMessage(Message message) throws Exception;
boolean deleteMessage(uuid messageid) throws Exception;
enum MessageType{
text,
voice,
file
}
//api to upload file for voice, video, attachment, return the file url
String uploadFile(File file)
//api to download file for voice, video, attachment, return the file uuuid
uuid downloadFile(File file)
class Message{
uuid messageid
String messageContent
String url//url if it is an attachment, a voice message, or video message
}
//using websocket api for user make call
makecall(uuid friendid) throws Exception;
//using websocket api for user facetime
makeFacetime(uuid friendid) throws Exception;
//api for user to search past history
Message searchHistory(String str) throws Exception;
User Table{
uuid userID, //Primary Key
String username,//add index
char[] password,
TimeStamp birthday,
String gender,
String lastLoginIpAddress
}
FriendShipTable{
uuid userID1,//Primary Key
uuid userID2,//Primary Key
long friendSinceStartTime
}
Message Table{
uuid messageId,//Primary Key
uuid, sender,//Foreign Key
Set
String messageContent,//index
String url//url to attachment like void, video, files
boolean isDeleted
}
flowchart TD
B["client"];
C{"server"};
D["Database"];
n1["node 1"];
B --> C;
C --> D;
C --> n1;
user send a username and password, first it go to the load balancer and forward to a host, then the API gateway will call the login function, then the host will send a query to user database with username, and password, if match, then generate a jwt token back to user, if not match then return wrongpassword exception or return user not exist exception.
user send user detail information including username, password, phone number ,email address etc to load balancer, and API gateway and call register server, register server(host) will check the user table if already exists or not, if not, insert a new row with user information, return succeed, otherwise return exception
user send message flow
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?