A basic understanding of tiktok's recommendation system
Published: 2022-11-19 13:15:08

I was initially reluctant to download tiktok because I thought all people did there was dance. After it became extremely popular and mainstream, I decided to see what the fuss was about. 
<img width="500%" style="width:100%" src="https://media.giphy.com/media/xUNda1EVzHcJOQY36w/giphy.gif">

I quickly graduated from using tiktok for 5 mins to spending hours on it due to the quality of its recommendation system on the for you page. I constantly feel like the application knows me because it is exquisite at suggesting content I want to interact with. 

<img width="500%" style="width:100%" src="https://media.giphy.com/media/iJP6mBmZyqKYTBmrav/giphy.gif">

The recommendation system seems to balance most of my interests with efficient distribution while suggesting content to me. This sparked my wait for the tiktok team to release something or anything that describes how their recommendation algorithms work. 

<img width="500%" style="width:100%" src="https://media.giphy.com/media/tXL4FHPSnVJ0A/giphy.gif">

Thankfully the Bytdance team (Tiktok's parent company) have released a [paper](https://arxiv.org/pdf/2209.07663.pdf) on how the things work in their recommendation system behind the scenes. 

<img width="500%" style="width:100%" src="https://media.giphy.com/media/JRbOlvIm3FOpW1h60f/giphy.gif">

Though this article intends to summarize the paper and make the system easy to understand, this is a severely over simplified summary of their recommendation system. To understand it in detail, please read the [paper](https://arxiv.org/pdf/2209.07663.pdf)

<img width="500%" style="width:100%" src="https://media.giphy.com/media/xZsfgxuBCMdLU9I6Hl/giphy.gif">

##Problem
So it's very normal for humans to have fleeting interests for very short amounts of time. This volatility in interests may happen down to the minute and can be due to a variety of factors such as emotion, mental wellbeing, location, season, time of the day, etc. This phenomenon is known as [Concept drift](https://en.wikipedia.org/wiki/Concept_drift).

So now imagine you use an application while watching a world cup game and then you search for videos about a football player. This user action may be used to suggest videos of the player during the tournament, award shows involving the player, football skill-move videos of the player, so on and so forth. However after the game, you move on to clicking the Formula 1 account to view highlights of a race but this time the suggested videos on your timeline are still about the footballer you searched for earlier on. This behavior may irritate users or reduce their interest in the application. As simple as it sounds, the Tiktok recommendation system is carefully designed to mitigate the tendency of this behavior generally known as [Concept drift](https://en.wikipedia.org/wiki/Concept_drift) as mentioned earlier. They call this system the **Monolith**

##Basic design
So a basic machine learning (ML) model uses patterns from data to predict results. In a ML model, these patterns in data are extracted by training the model with some form of historical data. This may be done repeatedly to help the model grasp the patterns properly. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dqnt9sum8abzoka5ejv3.png)

The problem with most models is that, the training process relies on an over-idealistic assumption that components in the training data appear frequently and are distributed evenly. This assumption is harmful to a model's quality because data is hardly ever uniform especially with respect to time. Also, prediction rates for these models deplete over time because training data isn't close enough to real-time user feedback. This phenomenon increases the failure rate of reflecting the latest interests of a user.

In light of these observations, the tiktok team designed the Monolith to 
1. Dynamically prepare data for training by intuitively adding and evicting components from training data.
2. Synchronize training data with real-time user feedback by engineering a loop service which feeds and runs the model to predict recent user behaviour.

<img width="500%" style="width:100%" src="https://media.giphy.com/media/5p2AWGqE5l8x3b8f4F/giphy.gif">

## Dynamic data preparation.
###frequency/occurrence filtering
The Monolith does dynamic data preparation by using a "less frequently used" policy. Components of data that are hardly used do not affect the quality of result in a ML model. Keeping such data increases the size of the training dataset which affects the speed of model preparation while consuming resources in vain. Obviously, removing such components increase model efficiency which is a good thing. An example of a direct rule or threshold in this policy is that, popular data components may appear a million times while unpopular ones may appear under 10 times. The Monolith goes the extra mile of using a probabilistic filter to compute the threshold for data component filtering. This enforces dynamism because the threshold of occurrence is not static.

### Stale removals
The Monolith also does dynamic data preparation by removing distant historical data that will not contribute to model quality because it is hardly used. So for example, if actions from a followed user contributes as factor to content suggestion on your timeline, this component will be removed if the user ceases to be active. The monolith determines the lifespan of data by attaching expiries to them. The dynamism is in the computation of expiry times for data components based on sensitivity to historical information. 

<img width="500%" style="width:100%" src="https://media.giphy.com/media/xUPGcIhlCUsGPutF9m/giphy.gif">

##Synchronize training
Though the monolith does training in 2 ways (Batch training and Online training), it is built with the capability of
seamlessly switching between them.
### Batch training
In the monolith, batch training is done only with historical data accumulated from user behaviour. This type of training is only deployed when fundamental changes are made to the ML model architecture to stabilize the model's baseline patterns.
### Online training
Unlike other recommendation systems, the monolith does not stop training when it is deployed into real life production environments. Instead it siphons real-time data on-the-fly which is synchronized with already existing data to train the model. This enables the monolith to interactively adapt itself according to a user’s feedback in real-time.

Synchronized training creates an environment for automated model improvements with minimal supervision which is ideal from an engineering point of view. 

### Advice for influencers
For influencers, if you didn't already know, factors that may affect content success include
1. How the video performed when first uploaded - engagement due to searches and tag priority
2. For how much time the video is watched on average - this suggests that videos should be kept short and precise to hold user attention. For longer videos, content must be interesting and easy to follow. Avoid context switching.
3. Number of likes, comments, downloads, and shares - For computer applications, numbers are usually a determining factor for segregation. The higher your numbers, the more your content will be pushed into the recommendation system.

These are very important as they tie into the core workings of the recommendation system. The target during content creation should be to get as much interaction on your video during its early stages. The algorithm seems to facilitate exponential engagement as users interact with it in the beginning. 
According to the inner workings of the recommendation system, uploading content and somehow linking it to previous/old content on your page may revive engagement for older videos.  This may work because the expiry time for adding features or tags related to your content may be increased to get your content in the recommendation system. A clever implementation of this may keep a set of videos in on your page in a high engagement loop. Good luck


##Conclusion
Though there is nothing heavenly brilliant about the monolith, it takes the mitigation of concept drift very seriously thereby increasing its accuracy of prediction. Making an effort to continuously use feedback from users is a testament of how much Tiktok cares about user experience and user satisfaction. Big congratulations to the team at Bytedance and tiktok for both writing a clever system and sharing the overall architecture. 

<img width="500%" style="width:100%" src="https://media.giphy.com/media/BPJmthQ3YRwD6QqcVD/giphy.gif">

Thanks for reading, I'm going back to scroll through Tiktok. 😂😅 See you in the next one.

<img width="500%" style="width:100%" src="https://media.giphy.com/media/BoHCeLmEKytt7oFxyR/giphy.gif">