banner



System Design For Messaging App

Chat messaging or Facebook messenger is a messaging app or platform. Now I am going to build a chat messaging service system design that will have the following features.

Below are the features that I would like to include in my application.

  • One to One Chating.
  • Online / Sent / Read updates.
  • Sending picture or other files.
  • Database ( For database I'm using Cassandra).
  • Security.
  • Distributed Cache ( For this I'm using REDIS).

How to Develop System Design for Facebook Messaging Services

Fig 1. Basic Structure of Application

From here I will take each and every scenario of the application and will explain as a case study.

Case-1: What will happen when the user will log in to Facebook Messenger?

When the user will log in to the application then we need a bi-directional connection between the user and the system to communicate with each other. Here are some applications that can be used for the bi-directional connection.

  • WebSocket
  • BOSH
  • Long Polling Http.

Here I'm using the WebSocket for bi-directional connection. When once the User is connected to the network, log in and authentication is done, then the user can talk to the Load Balancer. The Load Balancer further selects one of the servers for the communication.

Once the connection is done, hardware information is going to be stored in REDIS(Distributed cache). It maintains all-important information like User, Server and a Heart bit time. Below is the table, you can see.

User Server Heartbeat time ( last time user login)
User-A N2 17th Nov 2018

6:00:23 Pm

User-B N1 20th Nov 2018

9:00:34 Pm

Case-2: User-A is connected to the Node2(Server2), What if Node2 dies or gets down?

In this scenario, the Load Balancer will assign the other server to the user. It will not cause any problem.

Case-3: User-A wants to send the message to user B.

Structure When User-A sends messages to User-B

Fig 2. Structure When User-A sends messages to User-B

Database Schema

These following database table will require when user_A sends a message to user_B.

User  Table

User1 User2 Connection-id Encryption Key
UserA UserB 5 A5263524GHH655
UserA UserC 12 HJH787878GHGH

User Table contains the information of users, connections ids and encryption key. Connection id represents the unique connection between the users. It is automatically generated by the system when User-A and User-B are connected to each other. Whereas the encryption key is used to encrypt and decrypt the message.

Conversation Table

Conversation-id Time Text URL
5 6:54:33 "Hi, How're you?" abc.com/123?text=hi&fgghh

The conversation table contains the information like conversation ids, time at which the message has been sent, Text or message and URL.

Unread Table

From_User To_User Time
UserA UserB 12:34:23

The unread table contains the details of the unread messages, user details and time when the message has been sent to UserB from UserA.

 Read Table

From_User To_User Time
UserA UserB 4:32:21

The read table contains information like time and user details. When User_A sends a message to User_B.

Case-4: User-A sends a picture to User-B

Structure When UserA Sends a picture to UserB

Fig 3. Structure When User-A Sends a picture to User-B

Let's understand the A-Z scenario, what will happen when user-A sends a picture to user-B from the beginning.

  • UserA and UserB have already the connection-id and Encryption key, UserA first encrypts the picture using the encryption key.
  • Then the encrypted picture will go to the load balancer, further Node ( i.e N2) Then the N2 will send the encrypted picture to the Blob Storage. Blog storage will store the picture and sends the corresponding URL back to N2.
  • Then the N2 will store the conversation-id, time and URL in the Conversation Table.
  • Let's take UserB is connected to the Server3(Node3), then N2 will send the URL to the N3, Here N3 will download the picture with help of Ecncryted URL. Then It will send the picture to UserB.
  • Then the UserB can Decrypt the Image with the help of the encryption key and can view the picture now.

So, the above we have learned all scenarios of the chat messaging system (like a Facebook messenger or Whatsapp). In the next blog, we will go more deeply into the system designing and will learn the next system designing concepts Distributed Database System Key-Value Store concept.

System Design For Messaging App

Source: https://www.cronj.com/blog/how-to-develop-chat-system-design-like-facebook-messenger/

Posted by: oharacompay.blogspot.com

0 Response to "System Design For Messaging App"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel