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.
FUNCTIONALITY
ARCHITECTURE SYSTEM
WHATSAPP FRONT END
WHATSAPP BACK END
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.
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:
Source:Medium
Source: Medium
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.
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.
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.
It is convenient to replace the HTTP protocol, where when each user sends a request or signal to the server and a response is received, closes the connection, with the WebSocket protocol, which, although it is a bit more complicated, is a server that works very well for applications in real-time and that will always maintain a continuous connection between active users.
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.
The user A or sender who sends the info is connected to the server, but the recipient (user B) is not ; in this case the message is stored in the database and when the recipient connects, that message is sent again.
If the sender (A) is not connected to the server; then that message is stored (for example in a database like SQLite), and when it connects, it will be sent to the server.
However, if both are connected (A and B). The message is not stored but sent, it will travel through the pass-through server without staying there.
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.
Unlike one-to-one chats, keep in mind that for each group that is created in WhatsApp, a new GroupID will be generated, with an assignment of all the users that are included. When a message is sent to the group. The chat service identifies the recipient, which in this case will pass to the group service to locate the same group ID and who sent messages to all the user IDs in the list.
In this case, the web socket servers are not going to keep track of the group, but of the active users of the group. So when someone launches and sends a message to the group. The server contacts the message service and these will be stored in Cassandra. They are then saved to Kafka (which is a data transmitter), which will connect to the group message server and send them all. The server will connect to the group service, locate the list of group members, and deliver the message to each member individually.
The group service has control over all the information of the group, each one of the members, the user ID, group ID, until the time of creation, etc. data to be saved and stored in a MySQL database.
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.
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
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
Also published here.