Popularity decay algorithm for popular website posts
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In the digital age, the visibility of content often correlates with its popularity. Websites and social media platforms continually strive to present users with engaging and current content. However, as posts accumulate, managing their visibility becomes complex. Enter the popularity decay algorithm—a crucial method to prioritize content by both popularity and time-sensitivity. This algorithm ensures that users are exposed to not only the most popular but also the most relevant content.
Core Concept
The popularity decay algorithm modifies the numerical score that determines a post's visibility by applying a decay function over time. The core assumption is that the popularity of an item fades as it ages, thus older posts must be significantly more popular than newer ones to achieve the same visibility.
Mathematical Representation of Popularity Decay
Let's consider a basic function to represent this concept:
Where: • is the popularity score at time . • is the initial popularity score. • is the decay constant. • represents the base of the natural logarithm.
The decay constant determines the rate at which popularity decays over time. A higher value of signifies faster decay, making the post less visible as it ages.
Implementing Popularity Decay in Algorithms
Step-by-Step Example
We'll illustrate the implementation through a simplified example:
- Initial Scoring: A post is assigned an initial score based on upvotes, comments, and shares.
- Decay Application: The score decreases exponentially with time.
- Visibility Ranking: Posts are ranked in a feed based on their calculated score .
Consider the scenario where a post receives an initial score at time . If , the score after 10 hours will be:
This reduction emphasizes newer posts while still allowing exceptionally popular older content to remain visible.
Comparative Table
Below is a hypothetical comparison of two posts with different initial scores and decay observations:
| Post | Initial Score $ P_0 $ | Decay Constant $\lambda$ | Score after 10 hrs | |
| ---------- | ----------------------------- | --------------------------------- | ----------------------------------- |
| Post A | 150 | 0.1 | 55.37 |
| Post B | 200 | 0.1 | 73.83 |
As the table indicates, "Post B" retains a higher influence due to its superior initial engagement despite the same rate of decay.
Additional Considerations
Selection of Decay Constant
The choice of is crucial and depends on: • Content Frequency: Platforms with frequent posts might use a higher . • Engagement Dynamics: Slow engagement platforms might benefit from a lower decay rate. • Content Type: News articles might decay faster compared to timeless tutorials.
Popularity Boosters
To maintain dynamic engagement, platforms might include: • Re-boosting: A surge in interactions resets or adjusts the decay. • Content Typology: Allow different decay rates for varied content types.
Each of these methods influences how content is dynamically prioritized and helps retain user interest effectively.
Conclusion
The popularity decay algorithm ensures content relevancy by systematically decreasing visibility as content ages. As digital spaces become increasingly saturated, such algorithms are vital in crafting an engaging user experience. By expertly balancing the interplay between immediate popularity and time dynamics, platforms manage to deliver relevant content to users efficiently. Deploying such algorithms with appropriate metrics and variations can significantly enhance user engagement and satisfaction.
Related reading
- Predict classes or class probabilities?
- Predict NA missing values with machine learning
- Predicting a users next action based on current day and time
- Predicting Values with k-Means Clustering Algorithm
- Possible Interview Question How to Find All Overlapping Intervals
- Possible permutations of BST's input
- Prediction After One-hot encoding
- Prepend a level to a pandas MultiIndex

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.