Talk about the design and implementation of "SMS" channel

How long has it been since you sent a text message?

1. Background

Under the conventional distributed architecture, the "Message Center" service usually integrates the "SMS" channel as an important means of information access. Other commonly used means include: "Weibo", "Ting", " mail" etc.;

As for the design and implementation of "Message Center", it has been summarized in detail above. This article focuses on the way of SMS channel in the Message Center;

The implementation logic of SMS also follows the basic design of the message center, that is, after the message is produced, it is delivered and consumed through the message center, which is a typical production and consumption model;

2. Channel connection

In most systems, the realization of the SMS function relies on the SMS push of the third party. The experience of "Three-Party Connection" has been summarized before, so I won't repeat it here;

However, unlike conventional third-party docking, SMS channels usually connect to multiple channels to deal with various message delivery scenarios, such as common "verification code" scenarios, "notification reminder" scenarios, and "marketing promotion" scenarios;

There are several core factors that need to be considered here, such as cost issues, the stability of the SMS platform, timeliness, reach rate, and concurrency capabilities, which require comprehensive consideration of different scenarios;

Verification code : This scenario is usually a key interaction link between users and products, and it relies heavily on the timeliness and stability of SMS messages. If there is a problem, it will directly affect the user experience;

Notification reminder : This scenario is also closely related to the business, but relatively speaking, the timeliness of SMS delivery is not highly dependent, as long as it finally reaches the user within a certain time range;

Marketing promotion : The amount of data in this scenario is relatively large, and from the perspective of actual effect, there is great uncertainty, and the cost and concurrency capability of the SMS channel will be considered;

3. SMS channel

1. Process design

From an overall point of view, the implementation process of SMS can be divided into three sections: "1" the business scenario of SMS demand, "2" the SMS integration capability of the message center, and "3" the docking third-party SMS channel;

Demand scenarios : In the product system, there are many scenarios that need to use SMS, but the most important thing is to reach the user's information, such as identity verification, notification, marketing, etc., and the second is the internal important message notification;

Message center : Provides a unified interface method for message sending. Messages in different business scenarios are submitted to the message center for unified maintenance and management, and the corresponding push logic is adapted according to the source and destination of the message. SMS is only one of the methods ;

Channel docking : It depends on the specific demand scenario. If there is only a verification code docking requirement, you can only integrate one channel, or consider the cost as a whole, and dock multiple third-party SMS channels. It is recommended to consider certain scalability when designing;

2. Core logic

From the perspective of SMS management, the logical complexity is not very high, but it depends on the handling of details, and many subtle points that are not noticed may lead to push failure;

In fact, in the whole logic, in addition to the timeliness dependence of the "verification code" function, the SMS contact in other scenarios can be decoupled by selecting "MQ queue". In the design of the message center, it also has a high process complexity. Usability, the figure only focuses on describing the SMS scene;

3. Usage scenarios

3.1 Verification code

For the "Verification Code" scenario in the "SMS" function, I personally feel that it is the most complicated in conventional applications, which may involve the integration of "account" and related "business";

[ Verification code acquisition ]

This process is relatively short, as long as the verification of the mobile phone number is completed, it can be executed normally according to the SMS push logic;

What needs to be explained here is that in order to ensure the security of the system, the timeliness of the verification code is usually set, and it can only be used once, but occasionally due to the delay problem, the user may apply for the verification code multiple times. Based on the cache, it can be very good The data structure that manages this scenario;

Verification code consumption

The use of verification codes is very simple. Many products are now designed to weaken the concept of login and registration. As long as the verification code mechanism is passed, a new account will be created by default and related business processes will be executed;

Regardless of the "verification code" dependency in any business scenario, it is necessary to verify whether the "verification code" is correct or not when processing the process, so as to judge whether the process is executed downward. In some sensitive scenarios, it will also Limit the number of wrong verification codes to prevent account security issues;

3.2 SMS Reach

Whether it is "notification reminder" or "marketing promotion", the essence is to pursue the final reach of information. Most SMS operators can provide this capability, but the internal processing methods of the system are quite different;

In some business processes, it is necessary to deliver SMS messages to users. In the needs of marketing and promotion, it is more to send SMS messages in batches. In some requirements, there may also be a conversion rate statistics problem in terms of internal logic, and it is necessary to monitor the relevant SMS messages. interactive state;

4. Model Design

Since the SMS is integrated in the service of the message center, its related data structure models are all reused for message management. For details, please refer to the content of "Message Center", so I won't go into details here;

From a technical point of view, it involves the classic production and consumption model, third-party platform docking, task and state machine management, etc. As the basic service of the distributed architecture, the message center should also consider certain reusability in design.


Guess you like

Origin blog.csdn.net/cicada_smile/article/details/130877288