What is the basis for Weibo's follow-up? How to Design Databases

Source: Internet
Author: User
What is the basis for Weibo's follow-up? How to design a database? For example, I want to make a Weibo post, but follow this fast & nbsp; how to operate & nbsp; and write it in php .. ------ Solution ------------------ table structure & nbsp; estimation like double-stranded tables ------ solution -------------------- what do you know when you follow me on Weibo? How to design a database?
For example, I want to create a Weibo post, but I want to know how to use php to write the post ..


------ Solution --------------------
Table structure estimation like double-stranded table
------ Solution --------------------
Create a table with two fields:
Consumer id
Recipient id
------ Solution --------------------
I think Weibo is so popular that it is time to catch up with the development of smart phones.
------ Solution --------------------
Mysql is not used. These are all hot data. if you have a certain number of Weibo posts, you can check mysql directly.

In redis, n lists or sets or hash table + list are used. The name is the prefix + the id of the person who is called, and the content is the list or set of IDs of the person who is called. For example:

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


In fact, the most difficult design point is that the publisher posts a microblog, and all of his fans need to receive the message. I thought about how to implement this?
In particular, a star has millions of fans. There are two solutions:

1. data is actively pushed by the victim.
2. the publisher pushes a notification to the fans and then pulls data from the fans.

However, this means that tens of millions of people are required to send a message to access this message table or send a message to write data to the message Table of tens of millions of fans.

Because redis's data structure is too simple, it is very troublesome to use it to create a table. In fact, it is more appropriate to use mongo.

------ Solution --------------------
Reference:
In fact, the most difficult design point is that the publisher posts a microblog, and all of his fans need to receive the message. I thought about how to implement this?
In particular, a star has millions of fans. There are two solutions:

1. data is actively pushed by the victim.
2. the publisher pushes a notification to the fans and then pulls data from the fans.

However, this means that tens of millions of people are required to send a message to access this message table or send a message to write data to the message Table of tens of millions of fans.

Because redis's data structure is too simple, it is very troublesome to use it to create a table. In fact, it is more appropriate to use mongo.


I have never understood this question. I only have to worship it.
------ Solution --------------------
Reference:
Reference: in fact, the most difficult design point is that the publisher posts a microblog, and all of his fans need to receive the message. I thought about how to implement this?
In particular, a star has millions of fans. There are two solutions:

1. data is actively pushed by the victim.
2. the producer pulls data from the consumer's message table.

However, this means that tens of millions of people are required to access this message table or send a message ......


In fact, I also read what Sina Weibo's architect said. he only talked about the general idea. I thought about how to design the storage structure based on his idea, so it is not necessarily correct.

The first solution should be that everyone has their own message table. When a message is sent by the producer, the message is written to the producer's message Table, which contains the producer id, message content, and sending time. The biggest problem here is that you need to write data to tens of millions of tables.

Solution 2: each person's messages are only stored in his/her own message table, and are written after the message is sent by himself. Then, all of its consumers regularly fetch data from this table. Or when you send a message, send a notification to all consumers. for example, if you send a message of 1, the consumer will fetch data from the message table. This method causes a high number of concurrent read operations on this table when there are many followers.

Simply put, both solutions have advantages and disadvantages. However, there is still much room for optimization. Sina Weibo has used both solutions. In addition, I found some experience in this process.

In the first solution, they adopt an over-approval push policy, which divides users into several levels based on their activity levels. the push order is determined by their activity levels. Batch pushing reduces the burden to some extent.

In the second solution, the redundant multi-copy data load balancing method can be used to balance the concurrent read operations of that table. For example, I have a message table, but this message table stores n copies. on n servers, the content is completely consistent. When I send a message, I write data to the tables on these servers at the same time, or write data in batches. then, different fans will decide which server to read based on certain policies. Here, user activity can also be used as a parameter. fans with high activity can read data from server a (the message Table in server a is written preferentially when being written in batches)

There seem to be two solutions, but there are still many optimizations. for example, when reading data, add the cache layer to store only the messages recently published by each user, regularly archive data.
------ Solution --------------------
I think the really difficult part of this is the server architecture design, rather than the implementation method. An excellent method cannot cope with the increasing data volume. only by adjusting the server architecture and balancing the load is the long-term development path.
------ Solution --------------------
Can't you make it clear? Reference:
Reference: in fact, the most difficult design point is that the publisher posts a microblog, and all of his fans need to receive the message. I thought about how to implement this?
In particular, a star has millions of fans. There are two solutions:

1. data is actively pushed by the victim.
2. the producer pulls data from the consumer's message table.

However, this means that he needs tens of millions of visitors to send a message ......

------ Solution --------------------
Reference:
Can't you make it clear? Reference: reference: in fact, the most difficult design point is that the publisher posts a microblog, and all of his fans need to receive the message. I thought about how to implement this?
In particular, a star has millions of fans. There are two solutions:

1. data is actively pushed by the victim.
2. the hacker will be ......

Run the question
------ Solution --------------------
What you think is too complicated. it is true:
Reference:
Create a table with two fields:
Consumer id
Recipient id

------ 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.