“Bullet message” blew over the venture circle, online just 7 days, set off a huge wave IM industry. Netease cloud letter as bullet SMS IM and audio and video call technology provider, today to talk about bullet SMS this instant messaging product inside an important function – message roaming. Message roaming refers to instant messaging products that save users’ chat records in the cloud, and users can access all their chat records from any terminal device.

Talk about bullet SMS how to achieve message roaming

Message roaming is a relatively advanced function in the field of instant messaging, many social software does not provide this function, let’s analyze the technical implementation of bullet message roaming.

1. Bullet SMS instant messaging message exchange

Sender A sends the message to the business logic layer through connection layer X, and the business logic layer APP(which stores the online status of A and B) transfers the message to receiver B through connection layer Y, completing A message sending process.

2. Bullet SMS multi-terminal online message interaction

When multiple terminals are online, sender A sends A message to user B using A mobile phone and sends A notification to user A’s computer terminal to complete multi-terminal synchronization of the message

3. Realization of bullet SMS message roaming

Multiterminal message if the user interaction process A terminal is not online, so no one end of the online is not synchronized to the chat records, at this time will need to use message roaming function, when the sender to send A message to B, the APP will store messages, save in the Cache user’s recent chat records, DB USES the time series database, The chat history of the user is saved. The client saves the time stamp of message synchronization. When logging in, according to the time stamp, the data is pulled by the way of cache and history, so as to realize the roaming of complete session messages

How roaming messages are stored

Instant messaging generates a large number of messages. If message roaming is used, message storage becomes a challenge. First of all, there is a TimeLine for the messages generated by users in the session, which also needs to be stored according to the time. Diagram shows the two storage ways, 1 in the way of writing is according to the session to save, so save the message is that the benefits of A more personal message only, namely according to the session to store, but this approach has brought A problem, is to pull A message records for each session of the need to go to A read, read the diffusion; In 2, the write mode is saved according to the user. The advantage of saving messages in this way is that it is easy to read, but the messages of a session are saved for many times, resulting in write diffusion. The two storage methods described above have their own advantages and disadvantages. Which storage method is better?

First of all, let’s look at the application scenario of instant messaging. The writing of message records is very frequent, and the reading action generally occurs in the case of login is less. Let’s look at DB selection again: when using write diffusion mode, a message will write two records. When reading, all records can be queried at one time. In read diffusion mode, one message is written to one record, which needs to be read multiple times according to the number of sessions. Traditional relational databases struggle with read diffusion and can only be implemented by write diffusion. If noSQL database storage is used, both methods can be implemented.

Mixed storage of bullet text messages

Bullet SMS uses memory database + time series database storage. Memory database stores recent messages by read diffusion while time series database stores history messages by write diffusion. There are several considerations for such storage:

  • The high TPS and low RT of the in-memory database have little impact on the normal message sending and receiving of users. Asynchronous write is adopted to further improve the throughput

  • Memory data is stored in read diffusion mode. First of all, the cost of memory is relatively high and the space occupied should be reduced as much as possible. Second, the low RT of memory database can cope with the delay caused by read diffusion

  • The amount of historical messages is large, and the database storage medium is relatively cheap. Meanwhile, in order to ensure query performance, the storage mode uses the form of write diffusion, and the database supporting time series is selected, which has better read and write performance compared with the relational database

  • History messages are written asynchronously and have no impact on business processes

  • The client saves the timestamp of the last synchronization. In the case that the user uninstalls the application or does not log in for a long time, the read request falls on the in-memory database, providing a good user experience

Message roaming design concept of instant messaging platform

1. Centralized storage

As a communication Paas platform, it is necessary to provide a message content audit mechanism to the business side, but also to provide message data to the regulatory side. Centralized storage makes it easier to verify message content and can respond to regulatory requirements in a timely manner. The centralized IM system helps to implement the multi-terminal roaming function, which solves the problem of message synchronization when users switch accounts on multiple devices and in multiple scenarios, improving user experience.

2. Information security

In the system of the data access management: flat Taipei tend to use private cloud solutions, data center does not provide the network access, tenants have joined the network access will be limited to the security of data storage: use a proprietary protocol data encoding and encryption mechanisms to access news, even if the library can’t work out the message content In the aspect of data transmission protocol: Network communication uses customized codec packets and encryption algorithms. API interfaces support SSL encryption, supplemented by the service layer authentication mechanism, which effectively ensures the security of information transmission.

The above is a brief analysis of bullet SMS message roaming technology.