Notification system is the most basic function of a mature Web site or APP, such as Weibo, Zhihu, nuggets, etc. Of course, today this article is not to discuss such a large website, large traffic notification system, but the average number of users of the website or application.

The composition of the notification system

A notification system mainly consists of five parts: notification source, notification control, notification mode, notification template and notification target. The role of each component is described in detail below. The composition structure is shown in the figure below:

Informed sources

The notification source refers to the source that triggers the notification event. Generally, the notification source can be:

  1. Triggered by a user event: When other users comment, @, like, or leave a message on an object, the object owner needs to be notified. This is the most common scenario that requires notification.
  2. Automatically triggered after meeting the rules of the system: for example, when the system seals, level promotion, MEDALS, theoretically should be notified to the user.
  3. Administrator trigger: The administrator actively sends notifications, such as bulletins, to the whole network or to a user.

Notify the control

Notification control Is used for permission control, blacklist and whitelist filtering, message receiving frequency control, and content censorship. Anyway, everything about control and filtering goes here.

Notice the template

Notification templates are used to combine with the data model and finally present to the user, similar to V in the MVC pattern, and can be plain text or a template like Velocity. Notification templates are introduced to meet the following three goals:

  1. Different notification modes display different notification modes.
  2. Notification display is separated from notification model data;
  3. The notification template is available.

Inform the way

Common station letters, mail, SMS, work notice (nail, enterprise wechat), etc. Things like email, SMS, and work notifications are all based on third-party apps, and the best they can do is encapsulate the interface they provide, so there’s nothing to talk about. However, the in-site letter often needs to be designed and developed by the website or application itself, so many online introduction notification systems only introduce the design of in-site letter.

Layering of notification systems

The flow chart of notification system designed in this paper is as follows, which is mainly divided into business layer, data model layer, control layer, distribution layer, view layer and transmission layer. Layering reduces coupling between modules, with each layer doing its own thing.

The business layer

This layer is business-related and belongs to the notification source section of the notification system. Is the caller that invokes the notification system service and is placed here to illustrate the decoupling of the business from the notification system.

Data model layer

I believe that many programmers who write the Web background are familiar with the MVC pattern. This layer is equivalent to the M layer in the MVC pattern, which is mainly responsible for collecting model data. This layer is theoretically divided into notification sources for notification systems. The data model of this layer is closely related to the upper-layer business, and different business scenarios require different notification data.

Control/filter layer

Notification control is used for permission control, blacklist and whitelist filtering, message receiving frequency control, and content censorship.

Distribution layer

Different services often need different ways to send notification messages, for example, event notification needs to be notified by internal mail, while blocked accounts often choose email or SMS notification. After messages arrive at the distribution layer, different sending policies are selected based on different services. It can also be placed in this layer if you need to store records of sent messages.

The view layer

This layer has a lot to do with the data model layer, where the data is combined with the template to form the content to be sent.

Send a layer

It is mainly to call SMS, mail, work notice and station message and other interfaces to send messages out. In part 3, we will explain the site-in-message design in this layer.

The above layering suggests orchestrating all processes in a framework manner, with each layer invoked as an interface or abstract class. Each layer has some base classes and fixed interfaces that can be inherited and implemented by new businesses.

At the end

Notice system design here, although simple but also experience. The author is also slowly evolved when designing this piece. Start with little business and simple functions, and simply stack all the code together. The late additions are so large that they almost amount to refactoring. With this design, if new business needs to be added, just add a few classes and the process can run automatically.