IM instant messaging: how to design chat room architecture out of traditional thinking?

original
2018/06/30 06:00
Reading number 803

Because of the large-scale expansion of live video service, chat rooms have become popular in recent years. This article will focus on the typical chat room scenario and share it with you Netease Yunxin How to design the architecture when implementing this function.

 

Related recommended reading
How to design the server architecture when hundreds of thousands of people chat online in the live broadcast room at the same time?

High concurrency IM System Architecture Optimization Practice

 

Common virtual communities

The application scenarios of chat rooms are very wide. In addition to the traditional graphic chat, there are similar application scenarios in various popular products such as video screens, online shows, online education, and game interaction.

Before discussing chat rooms, let's learn about several common forms of virtual communities. The following table makes a simple comparison between the forum, IM P2P, IM group and chat room, which are common virtual community forms, from the dimensions of the number of participants, the immediacy of message delivery, and offline message attention. From this comparison, we can see that chat room is a virtual organization different from the forum and group mode, and the chat room architecture needs to be designed outside of traditional thinking.

The biggest difference between chat room and ordinary IM group (WeChat group, QQ group, etc.) is that it is a relatively open virtual organization. We can compare a chat room to a square. The square is open and has no boundaries, and all people can follow in and out. A group is like a room, a private organization with boundaries and a maximum capacity, and entering the room requires certain conditions, usually an active application or invitation to join. Compared with BBS forums, chat rooms have the characteristics of instant delivery of IM group messages and unlimited number of forum participants.

 

Key technologies and difficulties of chat room

So, can we transform a chat room from an existing mature technical framework?

After the previous comparison, we can see that chat rooms, forums and IM groups have certain commonalities. It seems that the forum architecture can be transformed into chat rooms, and IM groups can also be transformed into chat rooms.

Path 1 : To transform the forum architecture into a chat room, we first need to improve the immediacy of message delivery. Since the forums are based on HTTP protocol, in order to ensure instant message delivery, the client needs to constantly poll the server to obtain new messages. If the demand for immediacy is higher, the polling time needs to be shortened, This mode cannot be carried when the number of users reaches a certain scale. In order to ensure the efficient delivery of messages, a long connection mechanism needs to be adopted between the client and the server. The delivery of new messages is completed by the server actively pushing down to the client.

Path 2 : Transform an existing IM group into a chat room. Because the group has a high degree of attention to offline messages, all group messages need to be persistent when members are offline, so the more the group number is, the lower the efficiency is. For this reason, general IM groups have a maximum number of people. If you want to transform a group into a chat room, you cannot save offline messages, So it doesn't seem so smooth.

Many products that provide chat room services in the market are actually implemented based on the group model, so the maximum number of people has always been a bottleneck that is difficult to break through. Some services even directly use a special group model such as "super large group" or "thousands of people" to meet users' needs for chat room scenarios.

Let's take a look at the problems that need to be solved if we want to achieve a chat room service with an unlimited number of people.

First: client diversity. In recent years, the mobile Internet has developed very fast. The APP launched now generally needs to have different versions such as iOS, Android, Web and PC at the same time. The demand for cross platform development has always been a mountain in front of entrepreneurial teams;

Second: data security. The current network environment is extremely complex. The data communication between the client and the server of our APP is exposed in a complex public network environment. The nodes through which messages pass, whether there are packets caught in the middle, and whether data is collected maliciously are easily ignored by ordinary users. If the security requirements are ignored in the data communication process, it is easy to cause the leakage of user data, and data security is also important for the product;

Third: The problem of network failure or single point of service failure needs to be solved. No matter how well developers write code, they can't avoid unpredictable problems such as hardware failure or network failure. After the product accumulates a certain number of users, if they encounter service availability problems, they will lose users;

Fourth: The architecture needs to be flexible enough. It can support rapid horizontal expansion after the user level is increased, and will not need to be reconstructed due to architecture problems;

Finally: Message delivery is slow. Chat rooms have a very high requirement for the immediacy of messages. When the same message is delivered to different members, it needs to be completed with a millisecond delay. If the message is delivered slowly, the message timeline will be confused, and people in chat rooms cannot understand the context.

Based on these difficulties, we propose that chat rooms need to have these indicators: cross platform, data encryption, high availability, easy expansion, high concurrency and low latency.

 

Architecture of Netease Yunxin chat room

The above figure is Netease Yunxin The chat room hierarchical structure of.

Client layer : Handle compatibility issues of various devices, including language adaptation of ios, Android, Windows, Web and other development platforms; Management and maintenance of message channels, including weak network management on mobile devices, disconnection and reconnection; To ensure data security, all uplink and downlink data packets need to be encrypted and decrypted to avoid various security risks such as data leakage or man in the middle attacks.

Gateway access layer : Manage a large number of client connections, and the number of clients that can be maintained by a single node is in the order of hundreds of thousands; Dealing with protocol compatibility of different types of clients. Due to the diversity of client implementation technologies, the underlying data communication protocols between the client and the gateway are different, which requires protocol conversion by different access gateways; Processing data security logic; Cross network high availability logic, network level primary and secondary (who knows when the network cable will be cut off by Lanxiang graduates?); Efficient downlink distribution of broadcast messages, which distributes the received broadcast messages to all clients connected to this node.

Routing layer : As the transfer of service layer access, it also plays the role of load balancing and high availability. When the processing capacity of a single service node reaches the bottleneck, it is more convenient to expand. The routing layer makes the expansion of the service layer completely transparent to the front gateway layer; When a network service cluster fails, it can switch to the standby network to ensure service availability.

Business layer : Process the business messages in the chat room. There are many nodes in a cluster, and the roles of the nodes are equal. The failure of any node will reduce the processing capacity of the entire cluster, but will not cause service interruption, because other nodes can continue to take over the processing of business packets; The service cluster also has hot standby for multiple network environments to cope with possible regional network failures.

 

I still don't know what to do after reading the article? Then you can try to borrow the existing platform or tools. The current application needs to focus on how to catch users at the fastest speed. Netease Yunxin It is a good IM cloud platform for developers. With more than ten years of R&D accumulation, it is in the leading position in the country in terms of instant messaging technology. Netease Yunxin has applied for more than 60 IM patents so far, far exceeding similar products in the market. Welcome to discuss with us I M We also welcome you to pay more attention to NetEase Yunxin.

In addition, if you want to obtain more dry products and technical dry goods, remember to pay attention Netease Yunxin Blog Oh~

 

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
zero Collection
zero fabulous
 Back to top
Top