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 emoji, picture to other friends, read indicators,
user can send voice message and files to another friends
user can start a call and a facetime to another friends
the system should low latency
enough metrics to monitor performance
the system should support large scaling data
the system should fault tolerance
User estimation:
10 Million registered users, 10% of them are daily active users= > 1 million DAU.
Host estimation:
1000 connections per host => for 1M DAU => 1K hosts
Data storage estimation:
each user sends 100 message, each message avg 100 byte => 10KBs => stored in Relational DB => 10KB * 1M => 10GB
1MB 3 min voice message => 1 hour => 20 MBs for voice message
20 MBs for photos, files. => stored in S3 => 40MBs * 1M => 40TBs
1. function:
login
parameters:
String username,
char[] password
return:
bearer token with user info and expiration
throws:
credentialWrongException -> 401 HTTPCode
2. function:
Register
parameters:
String username,
char[] password,
String email,
String phone,
return:
bearer token with user info and expiration
throws:
userExistsException -> 400 HTTPCode
3. function:
sendMessage
parameters:
UUID senderID
UUID recipientID
String content
return:
message ID -> succeed -> 200 HTTP Code
throws:
internalErrorException -> 500 HTTP Code
4. function:
Message Management Operation
parameters:
UUID messageID
Operations:
search
update
delete
return:
UUID messageID
throws:
internalErrorException -> 500 HTTP Code
5.function:
Message puller
parameters:
UUID userID
DateTime currentTime
return:
List
throws:
internalErrorException -> 500 HTTP Code
InternalErrorException contains:
DependencyFailureException
...
relational DB :
user Table:
useriD: UUID -> Primary Key -> partition Key
password: encrypted charset
createdAt: timestamp
friendship Table:
user1ID: UUID -> PK
user2ID: UUID -> PK
startedFrom: timestamp
non-relational DB:
message Table:
messageID: UUID
content: string
createdAt: timestamp
updatedAt:timestamp
sender:UUID
recipient ID:UUID
hasRead: boolean
hasDeleted:boolean
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?