Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
```
communicate(stream inbound_message) stream outbound_message;
fetch_history({cur_message_id}) list of message
```
message
group_message
...
presence
service discovery: geological affinity
websocket: support bi-directional communication to minimize the traffic load on chat server and also gives the best performance
Each receiver will have a pub/sub channel for all the message sent to them.
message will be written to database for the future lookup.
Device syncup: when the user login, it sends the locally-kept cur_message_id to the chat server and the chat server can forward the history
presence: websocket between clients and the presence server. We maintain a channel for each user and all his/her friends subscribe that channel to get the update for the presence.
user login/logout: straightforward
user connection: we requires users to send heartbeat to show their health status.
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?