Site letter design

1. Online website internal information technology solution

"In-site letter" is different from e-mail, e-mail is sent and saved through a special mail server. And "in-station letter" is a message in the system. To put it bluntly, the realization of "in-station letter" is achieved by inserting records in the database.

There are two basic functions of "Intranet". First, point-to-point messaging. Users send internal messages to users; administrators send internal messages to users. Second, point-to-face messaging. The administrator sends mass messages to users (specified user groups that meet a certain condition). Point-to-point messaging is easy to implement and will not be described in detail in this article. In the following, according to different situations, we will talk about how the group sending of "in-station messages" is realized.

In the first case, the users in the site are a small number of levels. (tens to hundreds)

In this case, because the number of users is very small, there is no need to think too much about the optimization of the database. Using a simple table makes the design of the system simple, and it is easier to maintain in the later stage. It is a typical way to trade space for time way of doing.

The design of the database is as follows: Table name: Message

ID: number; SendID: sender number; RecID: recipient number (if it is 0, the recipient is everyone); Message: the content of the in-station message; Statue: the viewing status of the in-station message; PDate: the sending time of the in-station message;

If an administrator wants to send an internal message to everyone, it will first traverse the user table, and then insert the internal message into the Message table according to all users in the user table. In this way, if there are 56 users, 56 insertion operations are required to send an intra-site message in a group. This is relatively simple to understand and consumes more space.

After a certain user logs in, the sentence to view the letter in the station is:

Select * FROM Message Where RecID=‘ID’ OR RecID=0

In the second case, the number of users on the site is moderate (thousands to tens of thousands).

If you still follow the idea of ​​the first case. The consequence of sending an internal letter is basically that the background crashes. Because, to send an in-site message, you have to repeat thousands of inserted records. This is not the most important thing. The key is thousands or even tens of thousands of records. The content of the Message field is the same, and Message takes up a lot of storage space. For example, if the Message field has 100 Chinese characters and occupies 200 bytes, then 50,000 characters occupy 200×50000=10000000 bytes=10M. A simple in-site letter takes up 10M, which makes it impossible for people to live.

Therefore, the original table is split into two tables, and the main body of the Message is placed in one table to save space.

The database design is as follows:

Table name: Message

ID: number; SendID: sender number; RecID: recipient number (if it is 0, the recipient is everyone); MessageID: message number in the station; Statue: the viewing status of the message in the station;

表名:MessageText

ID: number; Message: the content of the internal message; PDate: the sending time of the internal message;

When the administrator sends an internal letter, a two-step operation is performed. First, in the MessageText table, insert the content of the station letter. Then insert a record for all users in the Message table, indicating that there is an in-site letter.

In this design, the main body information of the repeated intra-site messages (the content of the intra-site messages, sending time) is placed in a table, which saves a lot of storage space. However, when querying, it is more complicated than the first case.

In the third case, the number of users on the site is large (millions), and active users only account for a portion of them.

Everyone has such an experience. It is better to look at a website one day, and when the mood is surging, a user is registered. After a period of time, due to various reasons, I forgot the user name and password when I registered, and I no longer log in. Then the user is called inactive. From a practical point of view, inactive users account for a large proportion.

We have 2 million registered users, of which active users only account for 10%.

Even in the second case, sending an "in-site letter" would require 2 million insertion operations. But only 10% of them are valid, because the other 90% of users may never log in again.

In this case, we have to change our thinking.

The design of the database is the same as in the second case:

Table name: Message

ID: number; SendID: sender number; RecID: recipient number (if it is 0, the recipient is everyone); MessageID: message number in the station; Statue: the viewing status of the message in the station;

表名:MessageText

ID: number; Message: the content of the internal message; PDate: the sending time of the internal message;

When the administrator sends an internal letter, only the main content of the internal letter is inserted in the MessageText. No records are inserted into the Message.

Then, after logging in, the user will first query the records in the MessageText that are not recorded in the Message, indicating that they are unread in-site messages. When checking the content of the letter in the station, insert the relevant record into the Message.

This method is compared with the second one. If, active users are 100%. Both are the same efficiency. And the lower the proportion of active users, the more it can reflect the third kind of superiority. Only valid records are inserted, those that are not active will no longer take up space.

The above are my thoughts on the realization of the group "internal letter".

2. The basic model of the commodity has been demanded

The above is the approximate design plan of the website letter found by the search. I originally planned to use the second option. It was later dropped by PK. Let's talk about our product model and the needs of the station letter first.

write picture description here

The supplier has an item called Electric Kettle. Three distributors list the supplier's products separately. and rename the title of the item. They are called Electric Kettle A, Electric Kettle B, Electric Kettle C. They are all selling this item.

At this time, the supplier has withdrawn the product. Because the dealer ships from the supplier. The dealers themselves do not have stocks in stock. Goods are available.

There. All suppliers have removed items. These commodities need to be enforced by the system for lower-level dealers. At this time, it is necessary to send a message to these dealers in the station letter. Tell it the item is off the shelf.

But there is a problem here. for suppliers. The information seen in the inbox of the letter on the supplier's website should be "Electric kettle is off the shelf". However, the contents of the messages seen by distributors A, B, and C are "Electric kettle A is removed from the shelf", "Electric kettle B is removed from the shelf", and "Electric kettle C is removed from the shelf". That is, the message content is not exactly the same. The content of the message that the dealer sees is the title of the dealer's product.

Due to this requirement, the found solution was not finally adopted for the following reasons.

1. Not only do the inbox but also the outbox. Although it is a message caused by the same operation action. However, the content of the messages in the outbox and inbox are different. And everyone in the inbox gets different messages. If you use scheme two and scheme three. Keep only one message content. does not meet the needs

2. Our internal letter is only for sellers, not for buyers. All crowds reach the tens of millions. All can be done in a simpler way. easy to handle and maintain,

3, the station letter is not a mailbox. It is not necessary to keep all data all the time. Only keep data for a period of time

3. Design scheme

process:
write picture description here

write picture description here

Database Design:

write picture description here

Talk about the reasons for this design and the main points.

1. This is an internal letter, not a mailbox. You don't need to keep the data all the time. All to prevent data from growing, there will be a timed crontab script to delete message records older than 100 days. Here's 100 Days to Look at Product Demand

2. Although the message is sent by the system. But trigger person suppliers. All suppliers' outbox contents do not match the reseller's inbox contents. All Outboxes and Inboxes retain message content.

3. The outbox is equivalent to simply landing a piece of data. Because the caller needs to call the site message service to land the message. When all the landing news. There is no logic. Just a piece of data. This can quickly complete the operation of the caller itself. without blocking. No data is written to the outbox in the process.

4. As soon as there is a new message in the outbox. throw message. notification script. to process. Here the script is used instead of calling the interface. The reason is. First, the content of the message that each receiver needs to accept needs to re-aggregate other information. Message templates are subject to change. It is convenient to use the script to modify; Secondly, there are many people who send it. This sending will be time consuming. We generally call ourselves in a loop in the system. Instead, it is triggered externally. Our system is in the form of API calls. Every API has a timeout. If you put it in a function to loop the message to the inbox. The supermarket system will automatically end the function.

5. After the news has landed. It is very convenient to check the news in the inbox.

Summarize:

1)设计方案的时候。 一定要根据自己的应用场景来。

2)想问题要清晰和深刻。站内信不是邮箱。 有自己的特点。

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314742&siteId=291194637
Recommended