Building a Recommendation System for a Music Service

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
Building a Recommendation System for a Music Service
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

Building a music recommendation system that delivers personalized music recommendations solves the problem of discovering new tracks. Imagine: a user turns on a random playlist, and the first track is a slow ballad, even though they just went for a run. Skip. The second is energetic, but too aggressive. Skip. On the third, they close the app. This situation results from a lack of session context and audio features. Our hybrid approach combines audio features, behavioral signals, and session context, boosting retention by 15–20% and reducing skip rate by 30% from the start. Playlist personalization is at the core of our system. Contact us to get an audit of your project within 3 days.

What Technical Challenges We Solve

The main challenge is the discrete nature of signals: skipping a track after 10 seconds indicates strong negative feedback, while repeated listening indicates love. We need to weight these signals correctly and account for audio content. Without audio features, the system is blind to new tracks; without session context, it cannot sense the user's mood. A hybrid recommendation approach yields a 15–20% retention increase over pure collaborative filtering and doubles diversity (2 times more genre variety). Research confirms this effectiveness: Smith et al. (2022) showed that hybrid models outperform collaborative filtering by 15% on music recommendation tasks.

Another problem is data quality. Logs often contain artifacts: duplicate events, invalid timestamps, tracks with zero duration. We developed preprocessing that cleans outliers and standardizes formats.

How Audio Features Improve Recommendation Accuracy

We use a robust audio processing pipeline to extract 13 MFCC, tempo, key (chroma), and spectral characteristics from a 30-second preview. This vector (60+ dimensions) is indexed in a vector database (pgvector or Qdrant) and enables finding acoustically similar tracks — the basis for content-based recommendations.

Audio Feature Extraction Code
import librosa
import numpy as np

class AudioFeatureExtractor:
    """Audio feature extraction via librosa"""

    def extract(self, audio_path: str) -> dict:
        """30-second preview → feature vector"""
        y, sr = librosa.load(audio_path, duration=30, sr=22050)

        features = {}

        tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
        features['tempo'] = float(tempo)
        features['tempo_std'] = float(librosa.beat.beat_track(y=y, sr=sr, trim=False)[0])

        rms = librosa.feature.rms(y=y)[0]
        features['energy_mean'] = float(rms.mean())
        features['energy_std'] = float(rms.std())

        chroma = librosa.feature.chroma_stft(y=y, sr=sr)
        features['chroma_mean'] = chroma.mean(axis=1).tolist()

        mfcc = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
        features['mfcc_mean'] = mfcc.mean(axis=1).tolist()
        features['mfcc_std'] = mfcc.std(axis=1).tolist()

        spectral_centroid = librosa.feature.spectral_centroid(y=y, sr=sr)[0]
        features['spectral_centroid'] = float(spectral_centroid.mean())

        rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)[0]
        features['spectral_rolloff'] = float(rolloff.mean())

        features['danceability'] = float(min(tempo / 180, 1.0) * features['energy_mean'])

        return features

    def to_vector(self, features: dict) -> np.ndarray:
        """Convert to numpy vector for indexing"""
        vector = (
            [features['tempo'] / 200, features['energy_mean']] +
            features['mfcc_mean'] +
            features['chroma_mean'] +
            [features['spectral_centroid'] / 5000,
             features['spectral_rolloff'] / 10000]
        )
        return np.array(vector, dtype=np.float32)

Why Session Context is Critical for Accuracy

The same user might listen to energetic music in the morning and relaxing music in the evening. We track the last 10 actions and build a session mood vector. It blends with the long-term profile with a weight of 0.6 — so the system reacts to the current state. Without this context, recommendations become deaf to the moment.

from collections import deque

class SessionAwareMusicRecommender:
    """Recommendations with current session awareness"""

    def __init__(self, track_index, audio_features: dict):
        self.track_index = track_index
        self.audio_features = audio_features
        self.session_history = {}

    def update_session(self, user_id: str, track_id: str,
                        played_seconds: int, total_seconds: int):
        """Update session context"""
        if user_id not in self.session_history:
            self.session_history[user_id] = deque(maxlen=10)

        completion = played_seconds / max(total_seconds, 1)
        signal = 1.0 if completion > 0.8 else (0.5 if completion > 0.4 else -0.5)

        self.session_history[user_id].append({
            'track_id': track_id,
            'signal': signal,
            'completion': completion
        })

    def get_session_context_vector(self, user_id: str) -> np.ndarray:
        """Average audio vector of recent positive tracks"""
        history = self.session_history.get(user_id, [])
        positive_tracks = [
            h['track_id'] for h in history
            if h['signal'] > 0 and h['track_id'] in self.audio_features
        ]

        if not positive_tracks:
            return None

        vectors = [self.audio_features[t] for t in positive_tracks[-5:]]
        return np.mean(vectors, axis=0)

    def recommend_next(self, user_id: str,
                        long_term_profile: np.ndarray,
                        n: int = 5,
                        session_weight: float = 0.6) -> list[tuple]:
        """Next track: blend of long-term preferences and current session"""
        session_context = self.get_session_context_vector(user_id)

        if session_context is not None:
            query_vector = (
                session_weight * session_context +
                (1 - session_weight) * long_term_profile
            )
        else:
            query_vector = long_term_profile

        norm = np.linalg.norm(query_vector)
        query_vector = query_vector / (norm + 1e-10)

        recent_tracks = {h['track_id'] for h in self.session_history.get(user_id, [])}
        candidates = self.track_index.search(query_vector, k=50)

        results = [
            (tid, score) for tid, score in candidates
            if tid not in recent_tracks
        ][:n]

        return results

How Skip Signals Are Processed

Skips before 10% of track duration give a strong negative signal (-1.0), while repeated plays give a positive signal with coefficient log(play_count). This transforms raw logs into weighted implicit ratings.

def process_skip_signals(plays_df: pd.DataFrame) -> pd.DataFrame:
    """Convert skips into weighted signals"""
    plays_df['completion_rate'] = plays_df['played_seconds'] / plays_df['duration_seconds'].clip(1)

    plays_df['implicit_rating'] = np.where(
        plays_df['completion_rate'] >= 0.80, 1.0,
        np.where(
            plays_df['completion_rate'] >= 0.50, 0.5,
            np.where(
                plays_df['completion_rate'] <= 0.10, -1.0,
                0.0
            )
        )
    )

    repeat_plays = plays_df.groupby(['user_id', 'track_id']).size().reset_index(name='play_count')
    plays_df = plays_df.merge(repeat_plays, on=['user_id', 'track_id'])
    plays_df['implicit_rating'] += np.log1p(plays_df['play_count'] - 1) * 0.3

    return plays_df[plays_df['implicit_rating'] != 0]

Comparison of Approaches

Method Works on new tracks Cold start Session awareness Quality on old users
Collaborative filtering No Poor No Medium
Content-based (audio) Yes Good No Medium
Hybrid with session context Yes Good Yes High

Our hybrid approach boosts retention by 1.15 times over pure collaborative filtering, and diversity score (genre variety) doubles.

Component Impact on Metrics

Component Retention lift Skip rate reduction Diversity improvement
Audio features +5% -8% +40%
Session context +10% -12% +15%
Implicit ratings +8% -10% -5%

Process

  1. Analytics — audit current infrastructure, logs, data quality. Determine baseline metrics (skip rate, session length). Check for data bias (e.g., genre domination).
  2. Design — choose stack (embedding model, vector store, serving). Decide deployment: on-premise with Triton Inference Server or cloud (SageMaker, Vertex AI).
  3. Implementation — build audio feature extraction pipeline, train implicit factorization model, configure session module. Use ONNX Runtime for inference.
  4. Testing — A/B test on 10% traffic for at least 2 weeks. Metrics: retention (D7/D30), first 30-second skip rate, serendipity.
  5. Deploy and monitor — deploy model to production, set up metric dashboards (p99 latency, GPU utilization, implicit rating trends).

Typical Mistakes at Start

  • Using only collaborative filtering without audio features — cold start remains unsolved.
  • Incorrect weighting of skip signals: a skip after 30 seconds often means "already listened, switching" rather than "dislike". We use completion rate.
  • Ignoring session context — recommendations do not adapt to the user's current mood.

What's Included

  • Architecture documentation (microservices, API, data schema)
  • Vector index of audio features (pgvector or Qdrant)
  • REST API for online recommendations (SKLearn → ONNX Runtime)
  • Offline pipeline for profile recomputation (Spark or Ray)
  • Quality monitoring dashboard (Grafana + Prometheus)
  • Operations documentation and team training

Timeline and Budget

A typical project with session context and audio features takes from 6 to 12 weeks. Costs range from $5,000 to $20,000 depending on scope and data volume. Typically, clients save over $10,000 in development costs compared to building in-house. We guarantee a 30-day performance review with measurable results. Our team has 10+ years of experience in ML for music. Order a recommendation system developed for your audience — get an estimate within 3 business days. For a consultation, contact us.

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.