Understanding the Architecture of an Instant Messaging Service like WhatsApp

WhatsApp is one of the most widely used cross-platform messaging applications. On it, information is sent immediately, which is why more and more websites include it as another service to facilitate communication with users.

What will you read in this piece?

The two most popular types of chats are Facebook Messenger, which is responsible for saving all messages indefinitely, and the other is WhatsApp, which stores them until they are delivered. Once read and delivered by the target user, they are removed from the server and disappear.

Functionality

The advantage of a system like WhatsApp is that the communication and transmission of information is practically in real-time.

For this reason, when it comes to implementing and discovering the technical scenario of the architecture of an instant messaging system, we must think that it must include a series of functionalities so that it is minimally optimal, like the many of WhatsApp:

Architecture System

Source:Medium

Source: Medium

Profile Database

First, user information such as status, profile picture, profile ID, and contact details must be collected and saved.

It is essential to save in the cloud (for example in a similar service or like the one offered by Amazon’s S3 ) the images of the users, each one of them with their links.

Profile Service (API)

It is allowed to publish, add, update or even retrieve the information of each user.

The advantage of a system like WhatsApp is that the communication and transmission of information is practically in real time . For this reason, when it comes to implementing and discovering the technical scenario of the architecture of an instant messaging system, we must think that it must include a series of functionalities so that it is minimally optimal.

ChatServer

Mapping Database

It is also important to have a clear communication architecture. Users A and B use bidirectional communication to communicate over the network, so you need to know each other’s IP addresses.

This process ends with a server, users, load balancing (which distributes traffic between multiple servers and avoids network saturation), and the database.

Up to 65K ports will be open during the process. The socket controller will provide information about the web sockets connected to each user. Redis is used because it stores and is able to provide both which web socket controller a user is connected to, and whether to connect to another controller on disconnection.

Messenger Service. The API will obtain a repository of all message information through various filters such as user identification, message identification, delivery status, etc. For example, the open source big data solution Cassandra developed by Facebook can be integrated, which is capable of storing large amounts of information.

From here, several scenarios can happen and develop:

Data mapping: Every time a user sends a message, a new process is generated in which the information is stored. The chat server will spawn a new process for user A and with user B if he is online. The server identifies the receiver’s name through the PID (Process ID) and is immediately sent. The same process is repeated in reverse when user B is going to reply to user A.

Group chat service How does it work?

Last seen messages

The service offered by instant messaging and that allows you to check the “last seen” option uses a specific database that stores this information.

Technically every time a user opens WhatsApp, the server contacts this option to send the time details.

Messages with files or multimedia

WhatsApp front end

Each of the versions of WhatsApp is made with a different language:

Android version: with Java

iOS: with Swift

Windows Phone: C#

The web version: with JavaScript/HTML/CSS

The Mac desktop version: Swift/Objective-C

The PC desktop version: C/C#/Java

WhatsApp back end

Erlang is the primary language that has been used for WhatsApp.FreeBSD for the operating systemEjabberd is your application server XMPP

BEAM is your Erlang-based virtual machine

Mnesia is your Erlang-based database

YAWS is your multimedia web server

Lead Image credit


Also published here.