Best Practice to send News Feed content to the user

ยท

4 min read

Best Practice to send News Feed content to the user

Sending notifications or news feeds in an application like Twitter/Facebook is something that needs to be thought before implementing.

Considering the engineering aspect of Facebook or Twitter, as soon as you click on the home page you see a lot of new posts or tweets from the people you follow or from friends.

Technically, what happens- The software compiles a list of activities from all the profiles that a given profile is associated with and displays the result in an order using a Ranking Algorithm. The process sounds to be very simple but it's not that simple, a hell of a lot of coding and designing is required to get this right.

In this post, we won't deep dive into how do we get this news feed generated but learn different approaches used to send the news feed content to the user.

To further understand, keep in mind a system like Facebook, Instagram, or Twitter. These systems will help you better understand the approach.

Approach to send newsfeed content to the user

Pull

  • Allow the client/user to pull the content that is already generated on the news feed server.
  • This can be done regularly (using some scheduled job) or manually whenever needed.

Problem:

The client/user might not get the new data available on the server until a pull request is issued. Most of the time the pull request made might return no result if there are no new data available on the news feed server. You might see a lot of pull requests being issued with no new data. An operation that happens without resulting in any new data adds a negative effect on the system. You might use up resources on the system to do nothing and this is what we want to avoid.

Push

  • In this approach, the news feed server will push new data to users as soon as it is available. This approach is more real-time than waiting for an event to publish new data.

Problem:

To understand the drawback of this approach consider a system like Twitter where a user follows a lot of people or say celebrity user who has millions of followers in that case the news feed server has to push quite frequently causing a lot of traffic on the network. This might add to the low latency of the system.

Hybrid

The best way of sending newsfeed content to the user is by using a Hybrid approach.

  • For users with a high number of followers, we can use the PULL approach. The user who has a few hundred followers can use the PUSH approach.
  • In this method, we study the type of user in the system, next find how these users interact with the system or expect results from the system. Based on the above observations an approach is decided to send news feed to the different set users. This way we can optimize the resources used in the system, thus improving the latency.
ย