Implementation of a Recommendation System for Video Streaming

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1564 services
Implementation of a Recommendation System for Video Streaming
Complex
~2-4 weeks
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1347
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1247
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    948
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1183
  • image_logo-advance_0.webp
    B2B Advance company logo design
    642
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    921

Implementation of a Recommendation System for Video Streaming

Imagine a user opens a streaming service, sees a feed of content that doesn't interest them, and leaves for a competitor. Collaborative filters don't work—they don't account for the fact that in the evening the user wants to watch a comedy, but in the morning a documentary. To retain viewers, you need a recommendation system that understands context: time of day, device, mood, viewing history. Our approach is based on a context-aware model that has shown a 30-50% increase in viewing time in production. Budget savings from retaining existing users rather than acquiring new ones can reach 40%—for a platform with 1 million users, this translates to over $200k annually. For a mid-size platform (5M MAU), typical annual savings exceed $400k.

Key Metrics for Evaluation

The primary metric is session length (watch time). Additionally, we track episode continuation rate—the proportion of users who start the next episode of a series—and diversity of consumed content. CTR is secondary because the goal is retention, not clicks. Our online experiments show that the increase in viewing duration is 3-5 times higher than when using collaborative filtering.

Accounting for User Viewing Context

The key idea is to predict not just 'like/dislike' but the probability of completing the view given the current state. To do this, we build a user tower and an item tower with a common embedding space and add contextual features: hour of the day, device type, duration of the previous session, genre profile.

Context-Aware Model

import numpy as np
import pandas as pd
import torch
import torch.nn as nn

class VideoStreamingRecommender(nn.Module):
    """Takes into account viewing context: time, device, companions"""

    def __init__(self, n_users, n_items, n_genres, embed_dim=128):
        super().__init__()
        # User tower
        self.user_emb = nn.Embedding(n_users + 1, embed_dim)
        self.genre_emb = nn.Embedding(n_genres + 1, 32)

        # Context features
        self.context_mlp = nn.Sequential(
            nn.Linear(10, 32),  # hour, day, device_type, etc.
            nn.ReLU()
        )

        # Item tower
        self.item_emb = nn.Embedding(n_items + 1, embed_dim)
        self.genre_item_emb = nn.Embedding(n_genres + 1, 32)

        # Scoring head
        self.scoring = nn.Sequential(
            nn.Linear(embed_dim + 32 + 32 + embed_dim + 32, 128),
            nn.ReLU(),
            nn.Dropout(0.3),
            nn.Linear(128, 1),
            nn.Sigmoid()
        )

    def forward(self, user_id, context_features, item_id,
                 item_genre, user_top_genres):
        u = self.user_emb(user_id)
        g = self.genre_emb(user_top_genres).mean(dim=1)
        c = self.context_mlp(context_features)

        i = self.item_emb(item_id)
        ig = self.genre_item_emb(item_genre)

        combined = torch.cat([u, g, i, ig], dim=1)
        return self.scoring(combined).squeeze(1)


class WatchHistoryFeatureExtractor:
    """Features from viewing history"""

    def extract_user_features(self, watch_history: pd.DataFrame) -> dict:
        """
        watch_history: user_id, item_id, watched_seconds, total_seconds,
                       genre, timestamp, device
        """
        completion_rates = watch_history['watched_seconds'] / watch_history['total_seconds'].clip(1)

        features = {
            'completion_rate_avg': completion_rates.mean(),
            'completion_rate_std': completion_rates.std(),
            'binge_sessions': self._count_binge_sessions(watch_history),
            'preferred_genres': watch_history.groupby('genre')['watched_seconds'].sum().nlargest(3).index.tolist(),
            'preferred_device': watch_history['device'].value_counts().index[0],
            'avg_session_items': self._avg_items_per_session(watch_history),
            'evening_watcher': self._is_evening_watcher(watch_history),
            'weekend_preference': self._weekend_ratio(watch_history),
        }
        return features

    def _count_binge_sessions(self, history: pd.DataFrame) -> int:
        """Sessions with 3+ episodes in a row"""
        history = history.sort_values('timestamp')
        history['session_gap'] = history['timestamp'].diff().dt.total_seconds() > 1800
        history['session_id'] = history['session_gap'].cumsum()
        session_counts = history.groupby('session_id').size()
        return int((session_counts >= 3).sum())

    def _is_evening_watcher(self, history: pd.DataFrame) -> bool:
        evening_views = history[
            pd.to_datetime(history['timestamp']).dt.hour.between(18, 23)
        ]
        return len(evening_views) / max(len(history), 1) > 0.5

    def _weekend_ratio(self, history: pd.DataFrame) -> float:
        weekend = pd.to_datetime(history['timestamp']).dt.dayofweek >= 5
        return weekend.mean()

    def _avg_items_per_session(self, history: pd.DataFrame) -> float:
        if 'session_id' not in history.columns:
            return 1.5
        return history.groupby('session_id').size().mean()

How the Recommendation Works Step by Step

  1. Context collection: When a user opens the app, we gather device type, hour, day, previous session duration, and top genres.
  2. Embedding generation: The user tower produces a user embedding; the item tower produces embeddings for candidate items.
  3. Context fusion: Context features are processed via a small MLP and concatenated with embeddings.
  4. Scoring: The scoring head predicts the probability of completing the item given the context.
  5. Series boost: Candidates from series already started get a 2.5x multiplier if they are the next unwatched episode.
  6. Ranking: Boosted scores are sorted and the top-N recommendations are served via REST API.

The Importance of Series Content for a Recommendation System for Video Streaming

In streaming, series are the main driver of retention. A user who watches a series spends 3 times more time on the platform. Standard models don't prioritize the next episode, and the user may get lost among the recommendations. We implemented a module that increases the probability of the next episode by 2.5 times. Our method is 3-5 times better than standard collaborative filtering in watch time increase, and 2-3 times better than content-based approaches.

Ranking with Continuity Boost

class SeriesContinuationBooster:
    """Boost for the next episodes of series the user is watching"""

    def boost_continuation(self, candidates: list[tuple],
                            user_watch_history: pd.DataFrame,
                            content_metadata: dict) -> list[tuple]:
        """Increase priority for continuations"""
        # Series in progress
        series_progress = (
            user_watch_history
            .groupby('series_id')['episode_number']
            .max()
            .to_dict()
        )

        boosted = []
        for item_id, score in candidates:
            meta = content_metadata.get(item_id, {})
            series_id = meta.get('series_id')
            episode = meta.get('episode_number', 1)

            boost = 1.0
            if series_id and series_id in series_progress:
                watched_episode = series_progress[series_id]
                if episode == watched_episode + 1:
                    boost = 2.5  # Next episode
                elif episode <= watched_episode:
                    boost = 0.1  # Already watched

            boosted.append((item_id, score * boost))

        return sorted(boosted, key=lambda x: x[1], reverse=True)

Comparison of Recommendation Approaches

Approach Advantages Disadvantages Watch time increase
Collaborative filtering Simplicity, cold start No context, weak personalization +5-10%
Content-based filtering Works without history, considers genres Does not use collective behavior +10-15%
Hybrid (ours) Context and series awareness Requires more data +30-50%

The hybrid model provides a viewing duration increase 3-5 times higher than collaborative filtering, and 2-3 times higher than content-based methods. This is confirmed by A/B tests on projects with audiences from 500k to 5 million users.

Implementation Process for a Personalization Model

Stage Duration Result
Data and infrastructure audit 1-2 weeks Report on data quality, ETL schema
Model design and training 3-4 weeks Baseline model, experiments
Online experiments (A/B) 2 weeks Statistically significant metric improvement
Integration and deployment 1-2 weeks REST API, latency monitoring p99 < 50 ms

Typical Mistakes in Development

  • Ignoring context: the feed looks the same in the morning and evening.
  • Linear ranking: all features are weighted equally, no series prioritization.
  • Lack of monitoring: preference drift is not tracked.
  • Overfitting to popular items: the model recommends only the top 100, missing the long tail.

What's Included in Turnkey Development

  • Model with detailed documentation (model card, feature descriptions, metrics).
  • REST API for serving recommendations (latency p99 < 50 ms, throughput 10k RPS).
  • Infrastructure for online evaluation.
  • Integration with your platform (web, mobile apps, Smart TV).
  • Team training and post-launch support.

How We Ensure Quality

We have developed over 20 recommendation systems for streaming platforms over the past 5 years. Our experience confirms a 30-50% increase in viewing time within the first 3 months after implementation. We use Netflix as a benchmark but adapt the architecture to your specific content and audience. We guarantee transparency: you receive not a black box but an interpretable model with explanation for recommendations.

Example performance evaluation For one project (video service with 5 million users), we achieved: - session length: +35% - episode continuation rate: +40% - latency p99: 35 ms at throughput 5000 RPS - GPU utilization: 70% on inference with batch size 64

Order a preliminary data audit: we will analyze your audience and content and propose a system architecture. Get an expert consultation—a properly configured system pays for itself in the first months through increased viewing time and reduced churn. Typical investment starts from $50k with ROI within 6 months. With our expertise in over 20 projects, we deliver reliable solutions that retain users and boost engagement.

Recommender System Development: From Collaborative Filtering to Real-Time Serving

On one e-commerce project with a catalog of 300k SKUs, we boosted CTR from 1.8% to 4.4% — a 2.4x increase. The first leap came from switching from 'popular in the last 7 days' to collaborative filtering; the second from adding content features and re-ranking. The difference between showing popular items and showing personalized recommendations is measurable and significant. Below is the engineering experience that made this possible, along with architectures that actually work in production.

Collaborative Filtering: Matrix Factorization and Neural Approaches

Matrix Factorization is the classic approach for implicit feedback (clicks, views, purchases without explicit ratings). ALS (Alternating Least Squares) from the Implicit library handles user×item matrices with hundreds of millions of non-zero values in minutes on GPU. Latent factors 64–256, regularization λ=0.01–0.1 are starting parameters. Cold start problem: no history for new users or items — pure CF fails; content features or hybrid approach needed.

Neural Collaborative Filtering (NCF) replaces the dot product with a neural network. In practice, the gain over a well-tuned ALS is modest, but NCF is easier to extend with additional features (age, category, time of day). Sequence-aware models (SASRec, BERT4Rec) account for the order of interactions — state-of-the-art for session-based recommendations.

How to Choose Recommender System Architecture?

The answer depends on data, load, and cold start requirements. Below are three main approaches with selection criteria.

Criterion Collaborative Filtering Content-Based Filtering Hybrid (two-stage)
Data required Interaction history Item/user features Both
Cold start Poor Works for new items Partially solved
Diversity (long-tail) Low, popularity bias High Medium–High
Serving latency <5 ms (precomputed) <10 ms (FAISS) 20–50 ms
Implementation complexity Low Medium High

Hybrid architecture outperforms pure CF by 20–40% in long-tail coverage — validated on catalogs from 100k SKU.

Content-Based Filtering: When Interaction History is Scarce

Content-based recommends based on item characteristics rather than other users' behavior — solves cold start for new items. Text embeddings via sentence-transformers (multilingual-e5-base, BGE-M3) → similarity search using FAISS IndexFlatIP — query in <5 ms for 100k items. Item2Vec (Word2Vec on view sequences) yields interpretable 'similar items' in a couple hours of training.

Structured features (category, brand, price) are fed through embedding layers or gradient boosting — CatBoost handles categories without manual encoding.

Why Hybrid Models Work Better?

Production systems are almost always two-level. Stage 1 (Retrieval) — fast selection of 100–500 candidates from 300k items using ALS or Two-Tower model with vector search (FAISS, Qdrant). Stage 2 (Ranking) — heavy ranker on LightGBM or neural network with cross-features, time, device, and session context. LightFM is a good starting point for medium scale without heavy infrastructure. Our practice shows: moving from single-stage to two-stage yields a 15–25% accuracy improvement with only 20–30 ms additional latency.

Real-Time Serving: Architecture Under Load

Latency SLA — 50–100 ms at thousands of requests per second. Base recommendations precomputed (batch job hourly) → Redis by user_id → <5 ms. Real-time re-ranking via Kafka for events (clicks, cart adds) → update of context features. Feature serving — Redis with TTL (views in 24 hours, last clicked item). At 10k req/s, we deploy Redis Cluster with replication.

A/B testing is the only reliable way to measure improvements. Offline metrics do not always correlate with online. Kohavi et al., 'Online Controlled Experiments at Large Scale' (KDD 2013) — a must-read for the team. Test on 5–10% of traffic, monitor CTR, conversion, revenue per session. One of our client systems after hybridization increased revenue by 18% over a month of A/B.

Recommender System Development Timeline

The stages and typical time frames are in the table below. Costs are calculated individually based on catalog scale and latency requirements.

Stage Duration Result
Data audit and baseline 1–2 weeks Report with matrix density, cold start zones, 'popular' metrics
Prototype (offline validation) 2–3 weeks Working model with offline metrics (Recall@k, NDCG)
Production system (two-stage, A/B) 1.5–2.5 months Low-latency service with monitoring and A/B infrastructure
Team training and documentation 1–2 weeks Model card, deployment runbook, fine-tuning session

What's Included in Turnkey Development

  1. Data audit — user×item matrix density (typically <0.1%), activity distribution, temporal patterns, cold start statistics.
  2. Baseline — 'popular' as a simple threshold that is often hard to beat.
  3. Iterative improvement — ALS → content features → two-stage → sequence-aware. Each step with A/B.
  4. Serving infrastructure — batch precomputation, Redis, real-time re-ranking, Grafana monitoring.
  5. Documentation — model card with metrics, deployment instructions, feature descriptions.
  6. Team training — session on interpreting results and model fine-tuning.
  7. Support — 1 month post-launch (incident fixes, pipeline tuning).

We are a team with 7+ years of experience in recommender systems, having delivered over 30 projects for e-commerce and media. We guarantee transparent A/B testing and documented metric improvements.

Want to assess the growth potential of your catalog? Contact us for a free data audit. Order recommender system development — first prototype within two weeks.

Example ALS config for implicit feedback
from implicit.als import AlternatingLeastSquares

model = AlternatingLeastSquares(
    factors=64,
    regularization=0.05,
    iterations=15,
    use_gpu=True
)
model.fit(user_item_matrix)

More about the mathematics of recommender systems — in specialized literature.