Assume:
Storage:
500m * (7 * 256B + 2 * 1MB + 5MB) = 4PB / day
Bandwidth
4PB / 86400 s = 46GB/s
send + receive: 46GB/s * 2 = 92 GB/ s
/message
POST sendMessage(message_id, group_id, sender_id, receiver_ids, create_time, type, text, media_object=none, document=none)
GET getMessage(user_id)
/file
POST uploadFile(file_type, file);
GET downloadFile(user_if, file_id);
/list
GET getMessagelist(group_id, timeSpan) ๅ้กต
/group
POST group(group_id, users{}, owner_id, create_time)
GET group(group_id)
We need to store the metadata of groups, users and messages
For groups' and users' information, we can use the RDB (MySQL, PostgreSQL) because they are structured, but consider we will support 1B users; RDB is hard to horizontally scale. A NoSQL database like Cassandra would be better.
For the messages, we could also use Cassandra to store them, but for the media, we need to use a blob database.
Users:
userId
userName
createTime
lastLogin
Group:
groupId:
groupName
createTime
ownerId
members
We have 3 ways to implement message sending and receiving:
Components
ApiGateway: user auth
CDN: frequently used media
DB: for users and group metadata
Blob DB: media
cache: frequently used media and message
Load balancer: balanced forward the request to different server
Message queue: for those offline message
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?