Home> Web Front-end> uni-app> body text

How Redis implements feed flow

coldplay.xixi
Release: 2021-02-01 17:26:48
forward
1960 people have browsed it

TodayRedis tutorialcolumn let’s take a look at how to implement feed flow

How Redis implements feed flow

1 Introduction

Moments and Weibo are all feed streaming products. There are also picture sharing websites Pinterest and Huapet.com, which are another kind. Feed stream product in the form. Many apps will also have a module called News or Message Plaza, which are also feed streaming products.

Core Concept

  • Feed
    Each status or message in the Feed stream. For example, a status in Moments is a feed, and a Weibo post in Weibo is a feed.
  • Feed Stream
    An information stream that continuously updates and presents content to users. Everyone's circle of friends, Weibo follow page, etc. are all a feed stream.
  • Timeline
    A type of feed stream, Weibo and Moments are all Timeline type feed streams. However, because the Timeline type appears earliest, is the most widely used, and is the most well-known, Timeline is sometimes used to represent Feed. flow.
  • Follow page Timeline
    A page that displays other people’s feed messages, such as Moments and Weibo homepage.
  • Personal page Timeline
    A page that displays the feed messages you have sent, such as the photo album in WeChat and the personal page of Weibo.

2 Features

  • Multi-account content flow
    There will definitely be thousands of accounts in the feed flow system. You can follow, unfollow, add friends, block and other operations. As long as this condition is met, it can be designed as a feed flow system.
  • Unstable account relationship
    Due to operations such as following and unfollowing, the relationship between users in the system will always change, which is an unstable state.
  • Reading and writing ratio 100:1
    There is a serious imbalance in reading and writing, with more reading and less writing. The general reading and writing ratio is 10:1, or even above 100:1.
  • High requirements for message delivery
    For example, after sending a message to a circle of friends, some friends saw it and some did not. If the girlfriend did not see it, it may cause serious consequences. Emotional conflicts have serious consequences.

3 Category

  • Timeline
    Sort by the time of publication. Those published first are seen first, and those published later are ranked last. The top is similar to WeChat Moments, Weibo, etc. This is also the most common form. If the product chooses the Timeline type, it means that there are not many feeds in the feed stream, but each feed is important and needs to be seen by users.
  • Rank
    Sort by a non-time factor, usually according to the user's preference. The user's favorite is ranked first, and the second favorite is ranked last. This generally assumes that the user may see a lot of feeds, and the time the user spends here is limited, then the Top N results that the user most wants to see are selected for the user. The application scenarios include picture sharing, news recommendations, and products. Recommendations etc.

4 Difficulties

4.1 Storage

Because the feed in this project is relatively simple, it is analogous to space theory Therefore, MySQL storage can be used. If the feed stream has a relatively complex data structure, a NoSQL database should be used, which makes the storage more convenient and efficient, such as MongoDB or HBase.

4.2 Push

In the push scheme, there are three schemes, namely:

Pull mode

Also known as read diffusion, users take the initiative to pull the feed content of their followers.
That is, when a user (especially someone who follows a lot of people) triggers a behavior, pull their own updates, retrieve the user's follow list, and then retrieve new feeds based on the follow list. If a user follows too many people, querying the user's watch list also has a large data cost.

Push mode

is also called write diffusion. When a user adds a feed, the feed will be automatically notified to those who follow it (preferred).
That is, when a user triggers a behavior (such as posting on Weibo), his own behavior is recorded in the behavior table, and also corresponds to the user's fans table, inserting a feed for each fan. However, for big Vs with more than 10,000 fans, inserting a feed for each fan is very expensive to store data.

Use Redis Sorted Sets (convenient to sort Timeline by time) to maintain fans' feed collections. When bloggers add feeds, they actively push content to fans' feed collections, so that users can It is very convenient to quickly read from the collection

Push and pull combination

For example, on Weibo, most users have a few hundred account relationships, but some users have 1,000 Use it only if it exceeds 10,000 yuan.

Online push, offline pull

  • When big V posts news, they will only publish the news to fans who are online at the same time. Offline fans will pull the news after they come online. to complete push and pull.

Regular push, offline pull

After the big V posts the update, it will be pushed to the fan update table regularly in the form of a resident process.

5 Table Design


##Recommended (free):redis tutorial

The above is the detailed content of How Redis implements feed flow. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!