Chat messager provide text based instant messaging to its users. Example WhatsApp, Facebook messenger, telegram.
Functional requirements
Non-functional requirements
Additional requirements
We need to save user data and chat history.
User : userId, name, isOnline, creationtime, status, lastSeen
ChatHistory : UserId, friendId, partition, count, messages.
Which database to use?
Column oriented database like HBase or Cassandra.
User metadata:
{ userId: user_1; name: Bill; creationTimestamp: 10000; status: "Hey there I am on whatsapp"; isOnline: 1; lastSeen: null }, { userId: user_2; name: Steve; creationTimestamp: 10000; status: "Hey there I am on whatsapp"; isOnline: 1; lastSeen: null }
Bill’s chat history:
{ userId: user_1; friendId: user_2; count: 5 partition: 1 messages: { { sender: user1; text: "Hi"; timestamp: 10001 }, { sender: user2; text: "Hello"; timestamp: 10002 }, { sender: user1; text: "I am fine."; timestamp: 10003 }, { sender: user1; text: "How are you doing?"; timestamp: 10004 }, { sender: user2; text: "I too am fine. Thanks for asking."; timestamp: 10005 } } }, { userId: user_1; friendId: user_2; count: 2 partition: 2 messages: { { sender: user1; text: "Did you watch the movie yesterday? How was it?"; timestamp: 10006 }, { sender: user2; text: "It was awesome."; timestamp: 10007 } } }
Question:
If we have 1 million messages sent each second with average message size 0.1 KB we need to calculate how much data will be generated in next 5 years?
Answer:
User 1 and 2 are chatting with each other. User 1 sends the message to the chat server which forwards the message to user 2. Similarly user 2 sends the message to chat server which forwards it to user 1. The chat server parallelly saves the message to our column oriented database.
Which communication protocol should be used by our clients?
HTTP long polling
Let us check our non-functional requirements