Go back to Read free chapters

How to model rating likes and votes used in content feeds

Learn how to model rating calculation for users

 

How to model a Content Rating Algorithm

In this chapter we will look more into how to build a content rating implementation and how to program a simple content rating algorithm that can be easily extended. 

How to store and calculate content's ratings based on the user's likes, votes, +1, hearts or ratings

First of all we implement how to store the user's ratings. We have a simple Content class that has a message attribute that represents a String content, a microblog text message for example. 

How to calculate total rating points

We have a few different ways to model the content rating, one is to add the rating straight to the Content class and calculate the total points there. The other one is to crete a new Rating class and keep the separated user ratings there. For performance it is better to implement these both. Rating points are added to the total sum and Rating is stored to remember which user has rated which content. This prevents the user to rate the content multiple times. And to note that this has to be done inside a database transaction.

The total points are calculated straight as an integer inside the Content class. And the user's ratings are kept separated in a different class called Rating.

Content Rating algorithm modeling

Image of Content and Rating relation.

Next we have an Java Spring boot implementation of a rating algorith as a microservice.

What new ideas or thoughts this chapter gave you?