AI-Powered Hybrid Recommendation System for Mobile Apps
Pure Collaborative Filtering breaks on cold start. Pure Content-Based ignores social signals and gets stuck in filter bubble. Hybrid systems combine both — these power recommendation feeds of major platforms: Netflix, Spotify, Amazon.
Main engineering question isn't "do we need hybrid", but "how exactly to combine".
Three Combination Strategies
Weighted Hybrid — Score Weighted Sum
Simplest: final score = α × CF_score + (1−α) × CB_score. Parameter α can be dynamic — for new user α = 0.2 (CF weak, trust CB), for experienced user α = 0.7.
class WeightedHybridRecommender:
def __init__(self, cf: CFRecommender, cb: CBRecommender):
self.cf = cf
self.cb = cb
def recommend(self, user: User, candidates: list[str], n: int = 20) -> list[str]:
alpha = self._compute_alpha(user.interaction_count)
cf_scores = self.cf.score(user.id, candidates) # dict[item_id -> float]
cb_scores = self.cb.score(user.profile, candidates)
hybrid_scores = {
item_id: alpha * cf_scores.get(item_id, 0) + (1 - alpha) * cb_scores.get(item_id, 0)
for item_id in candidates
}
return sorted(hybrid_scores, key=hybrid_scores.get, reverse=True)[:n]
def _compute_alpha(self, interaction_count: int) -> float:
# linear growth: 0.2 at 0 interactions, 0.8 at 100+
return min(0.2 + (interaction_count / 100) * 0.6, 0.8)
Switching Hybrid — Strategy by Context
Instead of mixing scores — switch between recommenders entirely. Switch logic can be complex: CF for logged-in users with history, CB for guests, popularity-based for new users without onboarding.
// Android: strategy by user context
sealed class RecommendationContext {
object Guest : RecommendationContext()
data class NewUser(val preferences: List<String>) : RecommendationContext()
data class ActiveUser(val userId: String, val interactionCount: Int) : RecommendationContext()
}
class HybridRecommenderRepository(
private val cfApi: CFRecommendationApi,
private val cbApi: CBRecommendationApi,
private val popularApi: PopularityApi
) {
suspend fun getRecommendations(context: RecommendationContext): List<Product> {
return when (context) {
is RecommendationContext.Guest ->
popularApi.getTopProducts(count = 20)
is RecommendationContext.NewUser ->
cbApi.getByPreferences(context.preferences, count = 20)
is RecommendationContext.ActiveUser -> {
if (context.interactionCount < 15) {
// mix: 30% CF + 70% CB
mergeRecommendations(
cfApi.getPersonalized(context.userId, count = 6),
cbApi.getSimilarToHistory(context.userId, count = 14)
)
} else {
cfApi.getPersonalized(context.userId, count = 20)
}
}
}
}
}
Feature-Level Hybrid via Neural Network (Two-Tower Model)
Advanced: CF embeddings of user and item concatenated with CB features and fed into shallow neural network (2–3 dense layers). Model trained end-to-end to predict click probability. This Two-Tower architecture used by Google and Airbnb.
# Two-Tower model (simplified)
class TwoTowerModel(nn.Module):
def __init__(self, user_emb_dim=64, item_emb_dim=64, cb_features_dim=50):
super().__init__()
self.user_tower = nn.Sequential(
nn.Linear(user_emb_dim, 128), nn.ReLU(),
nn.Linear(128, 64)
)
self.item_tower = nn.Sequential(
nn.Linear(item_emb_dim + cb_features_dim, 128), nn.ReLU(),
nn.Linear(128, 64)
)
def forward(self, user_emb, item_emb, cb_features):
user_out = self.user_tower(user_emb)
item_input = torch.cat([item_emb, cb_features], dim=-1)
item_out = self.item_tower(item_input)
return torch.sigmoid((user_out * item_out).sum(dim=-1))
On mobile client, Two-Tower serving works via pre-computing item embeddings + FAISS ANN.
Mobile Integration: Caching and Recommendation Updates
// iOS: recommendation cache with TTL and background update
class RecommendationCache {
private let cache = NSCache<NSString, CachedRecommendations>()
private let ttl: TimeInterval = 300 // 5 minutes
func get(userId: String) -> [Product]? {
guard let cached = cache.object(forKey: userId as NSString),
Date().timeIntervalSince(cached.timestamp) < ttl
else { return nil }
return cached.products
}
func set(userId: String, products: [Product]) {
cache.setObject(
CachedRecommendations(products: products, timestamp: Date()),
forKey: userId as NSString
)
}
}
Recommendations refresh in background via BGAppRefreshTask (iOS) / WorkManager (Android) — user sees fresh content on app open without waiting.
Process
Data audit: CF signal availability, CB metadata quality, user base size.
Choose combination strategy based on task complexity and resources.
Develop serving layer with client-side caching.
A/B test: hybrid vs best single recommender → CTR, time in app, conversion.
Timeline Guidance
Weighted Hybrid with ready CF and CB components — 1–2 weeks. Two-Tower model from scratch — 4–6 weeks including data collection, training, deployment.







