Weibo attention is based on what to know you pay attention to me, younger brother I care about you? How the database is designed

Source: Internet
Author: User
Weibo attention is based on what to know you pay attention to me, I am concerned about you? How is the database designed?
Title, I want to be a micro blog, but focus on how to do it in PHP to write.


------Solution--------------------
Table structure estimation like doubly linked list
------Solution--------------------
Build a table with two fields:
Followers ID
The ID of the person being followed
------Solution--------------------
I think Weibo is such a fire, it should be the time to catch up with the development of smart phones hehe
------Solution--------------------
MySQL, don't say it. These are hot data, if really have a certain scale of micro-blog, check MySQL directly die.

With Redis, use n lists or sets or hash table+list. The name is the prefix + the ID of the followers, and the content is the list or collection of the followers ' IDs. Similar:

Owner:1 = {3,1,5,8,12,64 ...}
Owner:2 = {32,56,22,11,4 ...}
...


The hardest part of the design is the fact that the followers are sending a microblog, and all of his fans need to get the message. The landlord thought about this how to achieve it?
Especially a star, he has millions of thousands of fans. The solution has two ideas:

1 proactively push data by followers
2 A notification is sent by the followers to the fans, and then the data is pulled by the fans

But that means he's sending a message that requires thousands of people to visit the message table or send a message that requires writing data to thousands of fans ' message tables.

Because the data structure of Redis is too simple, it is very troublesome to use MONGO, although it can be implemented completely.

------Solution--------------------
Citation: The
hardest part of the design is the fact that a Twitter tweet is being sent by followers, and all of his fans need to receive the message. The landlord thought about this how to achieve it?
Especially a star, he has millions of thousands of fans. The solution has two ideas:

1 proactively push data by followers
2 A notification is sent by the followers to the fans, and then the data is pulled by the fans

But that means he's sending a message that requires thousands of people to visit the message table or send a message that requires writing data to thousands of fans ' message tables.

Because the data structure of Redis is too simple, it is very troublesome to use MONGO, although it can be implemented completely.


The question I've been trying to figure out, it's just a cult.
------Solution--------------------
Reference: The
most difficult point in the design is to send a microblog to the followers, and all of his fans need to receive the message. The landlord thought about this how to achieve it?
Especially a star, he has millions of thousands of fans. The solution has two ideas:

1 proactively push data by followers
2 by followers go to the message table of the followers pull data

But that means he's sending a message that requires thousands of people to visit this message table or send a message
...

In fact, I also look at Sina Weibo, the architect said, he only said the approximate idea, I was based on his thinking Lenovo storage structure design, so not necessarily completely correct.

The first scenario should be that everyone has a message table of their own. When the message is sent to the followers, the message is written to the followers ' message table, with the content being the subject ID, the message content, and the sending time. The biggest problem here is to write data to tens of millions of tables.

In the second scenario, everyone's messages are stored only in their own message table, and when they send their messages, they are written. The data is then periodically taken from this table by all of its followers. Or when you send a message, send a notification to all followers, such as sending a 1, the followers will come to their own message table to fetch data. This way, when a person has a large number of fans, it will cause the table to be very concurrent read operation is very high.

In simple view, both options have pros and cons. But there is still a lot of room for optimization. Sina Weibo two programs have been used. And in the process has also explored some experience.

The first scenario, they take a partial push strategy, will divide the user by the active degree several levels, the push order is according to the user activity level to decide. Partial push reduces the burden to a certain extent.

The second scheme can use redundant multiple data load balancing method to balance the concurrent read operation of that table. For example, I have a message table, but this message table stores n copies, on n servers, the content is exactly the same. When I send messages to the tables of these servers to write data, or write in batches, and then my different fans, according to a certain strategy to decide which server to read. It is also possible to use user activity as a parameter, active fans go to server A read (the message table in Server A is the first to write in batches)

If you want to go, the solution seems to be two, but there are many things that can be optimized, for example, when reading data, adding the cache layer, the cache layer only stores the most recently published messages for each user, and the data is archived regularly.
------Solution--------------------
I think this really hard place is the server architecture design, not the implementation method. Again excellent methods, can not cope with the increasing volume of data, only to adjust the server architecture, the pressure is balanced open, is the long-term development of the road.
------Solution--------------------
Can't you just say something that makes you understand? References: References: the
Most difficult design point is the fact that a tweet is being sent by followers, and all of his fans need to receive the message. The landlord thought about this how to achieve it?
Especially a star, he has millions of thousands of fans. The solution has two ideas:

1 proactively push data by followers
2 by followers go to the message table of the followers pull data

But that means he's sending a message that requires thousands of people to visit
...
------Solution--------------------
Citation:
Can't you say something that makes you understand? References: References: The most difficult design point is the fact that a tweet is being sent by followers, and all of his fans need to receive the message. The landlord thought about this how to achieve it?
Especially a star, he has millions of thousands of fans. The solution has two ideas:

1 proactively push data by followers
2 by the followers to be
...
It's irrelevant.
------Solution--------------------
You're thinking too complicated, that's all:
Reference:
build a table, two fields:
Followers ID
The ID of the person being followed

------Solution--------------------
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.