output-onlinepngtools-7

How thin are the benefits of Redis caching?

Introduction:
OpenVidStreamer is my open-source video-sharing platform that revolutionizes user engagement through a unique economy. It rewards users financially based on their videos’ watch time and operates on a subscription model to incentivize active participation. The platform leverages advanced recommendation algorithms to enhance the user experience, delivering personalized video suggestions based on user preferences and habits.

The Role of Caching in the Recommendation System:

I have implemented a Cache-Aside pattern using Redis for the recommendationAlgo microservice. The caching strategy focuses on storing computed results rather than raw data, optimizing response times for user recommendations. The data items and their respective caching intervals are as follows:

  • User Favorite Categories: 24 hours
  • Popular Videos: 24 hours
  • Similar Users (those who liked similar videos): 20 minutes
  • User’s Liked Videos: 20 minutes

By caching these computed datasets, we ensure that the recommendation algorithm recalculates them only after their cache expires. This approach fine-tunes user recommendations approximately every 20 minutes, rather than with every query. We are considering extending the cache lifespan to further reduce load on the system.

Benchmark Results:

The introduction of caching has added a performance increase of approximately 15% with the exception of GetAlgoRecommendationsForUser as evidenced by the following benchmark results:

Method

Mean

Error

StdDev

GetUserPreferredCategories_New

387.2 μs

7.54 μs

7.74 μs

GetUserPreferredCategories_Old

443.7 μs

8.81 μs

10.14 μs

GetPopularVideosInGeneral_New

381.6 μs

2.43 μs

1.90 μs

GetPopularVideosInGeneral_Old

463.3 μs

7.04 μs

6.58 μs

GetPopularVideosWithExcludedWatchedForUser_New

780.6 μs

9.32 μs

7.78 μs

GetPopularVideosWithExcludedWatchedForUser_Old

899.1 μs

10.72 μs

9.50 μs

GetAlgoRecommendationsForUser_New

2,839.1 μs

36.18 μs

32.08 μs

GetAlgoRecommendationsForUser_Old

1,836.4 μs

28.32 μs

26.49 μs

Legends:

Mean : Arithmetic mean of all measurements

Error : Half of 99.9% confidence interval

StdDev : Standard deviation of all measurements

1 us : 1 Microsecond (0.000001 sec)

Outliers:

RecommendationRepositoryBenchmark.GetUserPreferredCategories_Old: Default -> 1 outlier was removed (480.21 us)

RecommendationRepositoryBenchmark.GetPopularVideosInGeneral_New: Default -> 3 outliers were removed (394.32 us..397.25 us)

RecommendationRepositoryBenchmark.GetPopularVideosWithExcludedWatchedForUser_New: Default -> 2 outliers were removed (827.40 us, 827.51 us)

RecommendationRepositoryBenchmark.GetPopularVideosWithExcludedWatchedForUser_Old: Default -> 1 outlier was removed (938.24 us)

RecommendationRepositoryBenchmark.GetAlgoRecommendationsForUser_New: Default -> 2 outliers were removed (2.96 ms, 2.97 ms)

Analysis and Future Work:

The GetAlgoRecommendationsForUser method initially performed all calculations within the database, resulting in a single request. However, with caching, this has changed to two separate calls to Redis, followed by a simpler database query, totaling three requests. The additional requests for “similarUsers” and “likedVideos” have inadvertently slowed performance.

To address this,I can instead add a 20-minute cache for algorithm recommended videos per user, and on request filter by excluding already watched videos. This modification should reduce database load while maintaining or improving performance.

Conclusion:

The integration of caching into the recommendationAlgo microservice has demonstrated promising results, improving efficiency and response times for user recommendations. Ongoing optimizations and adjustments will focus on enhancing performance further, particularly for the GetAlgoRecommendationsForUser method.

Tags: No tags

Comments are closed.