In terms of permission management, WeChat uses "labels" to group users, and the grouping of these labels is consistent with the WeChat address book. In terms of data, a "label" mark is added to each relationship. It should be noted here that although the relationship of WeChat is two-way for users in product use (i.e., following each other), when storing, relationship data is established for two related users, that is, each person has his own "address book". This can be seen by the fact that after deleting one's own friends, one does not delete oneself from other people's address books. This is the basic data of label grouping, which is also the basis for the subsequent permission management of Moments. For the messages that can be seen in the personal Moments timeline, the general logic is to first obtain all friends' messages, then remove the messages that are not authorized to be read by oneself, and remove the messages of users blocked by oneself, and then obtain the timeline that one is currently seeing. If this logic is used, it means that every time you refresh the Moments, you have to go to all the message pools to find the messages of the friends in the above address book, and you have to determine whether the user has the permission to read each message found. This is obviously an inefficient method, not to mention that WeChat has such a large number of visits and data. Therefore, this data structure design is not feasible. The process of reading each time in Moments under general logic Using scattered time for relational computingThe general idea to solve this performance problem is to spread the processes that require large amounts of computing to scattered time during normal times. The idea here is: prepare the timeline data required by each user according to the permission settings at ordinary times, and when it is needed (refreshing the circle of friends), directly read the prepared content. Then the answer is: in addition to storing a copy of the basic information such as text, pictures, etc. mentioned above, you also need to store a copy of the timeline data for each user. Note that it is one copy for each user. Of course, the "each copy" here does not need to store complete information, only the message ID and time (may be required). When everyone refreshes their own circle of friends, they only need to read their own data, without having to filter in the message pool or judge user permissions. How do you implement permission control? New messages generate new permissionsWhen a user publishes a message, the relevant permissions are set according to the tags mentioned above, and the server will write the message into the timeline of each user who has the permission to receive the message. That is, the permission arrangement is done at the moment the user publishes, rather than waiting until the reading time. This naturally reduces the amount of calculation when reading and improves efficiency. Permission control during publishing (schematic diagram, it is actually more complicated than this) As for the sharding of databases and tables, I won't go into details. Just know that it exists. Sometimes this kind of technical design will also limit the design of the product. So how do we prove that what is said above is reasonable? Interested students can test it: first send a message with reading permissions, such as allowing people in a certain tag to read it. Then add a new person to this tag. The result is that the new person cannot see the message, because the permissions are divided when the message is posted. The new person joins the tag after the message is posted, so he cannot get the permission allocation opportunity for the message. Although he is in the tag group later, he still cannot see the message. As an observer of WeChat design, the above answer is from the perspective of a user's system analysis. It does not mean that WeChat is indeed designed in this way, but the solution in the answer has been verified as much as possible. The answer does not involve specific technology, but is just a system analysis idea. |
<<: Are you suffering from developer ALS?
>>: Cocos Developer Salon——Cocos Studio V2.1 Open Plan
On September 10, Tencent Global Digital Ecosystem...
1. The "U" of a server is a unit that r...
Huaihua City, also known as Hecheng, was called H...
As Honor of Kings becomes more and more popular, ...
Here I would like to share 6 carefully selected b...
[51CTO Quick Translation] The emergence of techno...
How much does it cost to produce the Suzhou women...
√ With 150 million daily active users, the first ...
After Windows 10 2004 separated Cortana and the s...
This article is reprinted with permission from AI...
Today I want to share with you how companies can ...
Tsinghua University famous teacher's financia...
If 2020 is the first year of private domain, 2021...
Imagine that you get up in the morning and sit on...
If public domain traffic is the ocean, then users...