Building Dual-Surface Content Recommendation Systems
Machine LearningModel answerLast updated
Design a recommendation platform that serves both an on-demand content feed and selective push notifications, balancing relevance with user attention costs.
You're building a content discovery platform that needs to serve recommendations through two different channels:
- Content Feed: Users browse a personalized stream whenever they open the app
- Push Notifications: The system proactively alerts users about particularly relevant content
Both channels draw from the same content corpus but operate under different constraints. The feed can show many items with low individual cost per impression, while each notification consumes user attention and risks causing annoyance or opt-outs.
Scale and Constraints
- 100 million daily active users
- Billions of content items, with millions added daily
- Feed requests must complete in under 200ms (p99)
- Notification budget: 0-3 per user per day
- Content signals (likes, saves, dismissals) should influence recommendations within minutes
- Support users and content with no prior interaction history
What to Design
Describe how you would architect this system, covering:
- Feature Engineering Pipeline: How do you generate features for both batch training and real-time scoring?
- Retrieval and Ranking: How do you select candidates and score them for each surface?
- Exploration vs Exploitation: How do you balance showing familiar content against discovering new interests?
- Notification Decision Logic: How do you decide whether a piece of content merits interrupting the user?
- Metrics and Safeguards: How do you measure success and prevent degrading the user experience?
Hints
Hint 1
Consider that notifications have a real cost—users can disable them entirely. How does this change your optimization objective compared to feed ranking?
Hint 2
New content and new users arrive continuously. Your retrieval strategy needs to surface items with no engagement history yet.
Hint 3
User actions like 'hide' or 'not interested' are rare but carry strong signal. How should your model weigh these compared to positive actions?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Solution: Dual-Surface Recommendation Architecture
1. Establish Scale Parameters
Begin by translating user numbers into system requirements:
- Daily traffic: 100M users × 5 sessions × 3 feed loads = 1.5B requests/day ≈ 18k QPS average, 55k peak
- Content volume: billions of items with millions arriving daily means cold-start is continuous, not exceptional
- Latency breakdown (targeting p99 < 200ms):
- Candidate retrieval: 40ms
- Feature hydration: 30ms
- Model scoring: 70ms
- Post-processing: 20ms
- Buffer: 40ms
The fundamental difference between surfaces: feed views are opt-in, notifications are interruptions. This asymmetry drives distinct optimization goals.
2. Data Infrastructure
Feature Platform Architecture
Implement a unified feature store that serves both training and inference, preventing train-serve skew:
Batch Pipeline (hourly/daily via Spark):
- User interest embeddings from 30/90-day interaction history
- Content quality scores (engagement rates, creator reputation)
- Graph-based features (content similarity networks)
- Topic affinity distributions
Streaming Pipeline (seconds via Flink):
- Recent action sequences (last 20 interactions)
- Rolling engagement metrics (1-hour, 24-hour windows)
- Intra-session context (time on platform, topic drift)
- Notification fatigue indicators (recent sends, dismissals)
Critical pattern: Log features at serving time alongside requests, then join labels asynchronously. This "log-and-wait" approach ensures training data reflects the actual feature distribution at inference.
Event Flow
User Actions → Kafka
├→ Stream processor → Online KV store (millisecond lookups)
└→ Data warehouse → Batch jobs → Training datasets + embeddings
3. Candidate Generation Strategy
Blend multiple retrieval sources, each allocated a quota to ensure diversity:
For Feed (retrieve ~5,000 candidates):
- Personalized ANN: Two-tower model embeddings in HNSW index (60%)
- Graph traversal: Random walks from recently saved content (15%)
- Social signals: Items from followed creators/boards (10%)
- Trending content: High recent engagement across similar users (10%)
- Fresh exploration: Recent items (< 24h) scored by content features only (5%)
For Notifications (retrieve ~100 candidates):
- Use the same sources but weight toward high-confidence personalization
- Require minimum content age (avoid showing what they'll see in feed anyway)
- Filter out items already viewed or dismissed
4. Ranking Models
Multi-Task Neural Ranker
A transformer-based architecture that processes the user's recent action sequence and predicts multiple outcomes:
Predicted probabilities:
- p(save), p(click), p(long_view), p(share) — positive signals
- p(hide), p(dismiss) — negative signals
Composite scoring function:
score = Σ w_i · p(action_i) - penalty · p(negative)
Key modeling choices:
- Negative action weighting: Hide/dismiss events are rare but highly informative—use 5-10× higher loss weights
- Position bias correction: Include position as a feature during training, fix to a neutral value at serving
- Multi-task learning: Share representations across prediction heads to improve data efficiency
Feed-Specific Refinements
After heavy ranking reduces to ~500 candidates:
- Diversity re-ranking: Apply maximal marginal relevance to avoid topic repetition
- Exploration injection: Reserve 5-10% of positions for under-exposed content with uncertainty bonuses
- Contextual adjustments: Boost/suppress categories based on time of day, session length
Notification-Specific Model
A separate model estimates incremental value:
utility = p(engage | send) · value - λ · p(fatigue_event | send)
Where fatigue events include dismissals, turning off notifications, or creating a dismissal streak. The key insight: estimate the counterfactual—would this user have seen this content organically? Use uplift modeling (T-learner or causal forest) trained on randomized holdout experiments where some notifications were suppressed.
5. Notification Decision System
Budget Allocation
Implement per-user caps that adapt to behavior:
- New users: max 1/day
- Engaged users: up to 3/day
- Users showing fatigue signals: reduced automatically
Use a global budget constraint via Lagrangian multiplier λ, tuned so platform-wide opt-out rate stays below threshold (e.g., 0.1%/week).
Send-Time Optimization
Train a small model predicting open probability by hour-of-day from historical patterns. Queue batch notifications for each user's optimal window rather than sending immediately.
Deduplication
Maintain a short-term cache of recent feed impressions per user. Suppress notifications for content already shown in-feed within the last 24 hours.
6. Exploration vs Exploitation
Feed exploration (lower cost):
- Allocate explicit slots (5-10%) to exploration candidates
- For cold-start content, rely on content-only embeddings (visual, text)
- Apply UCB-style confidence bonuses to under-exposed items
- Track per-user exploration tolerance (reduce if they frequently hide new content)
Notification exploration (higher cost):
- Much lower rate (1-2% of sends) since bad notifications cause permanent damage
- Explore across content categories rather than random items
- Gate on minimum relevance threshold even for exploration candidates
- A/B test exploration strategies on small user cohorts first
Cold-start handling:
- New users: Use onboarding selections, geographic/locale defaults, and rapid learning from first interactions (weight first 5-10 actions heavily)
- New content: Content embeddings enable immediate retrieval; bootstrap engagement priors from similar existing content
7. Evaluation Framework
Feed Metrics
Offline: AUC per prediction task, ranking precision@k, calibration error Online:
- Primary: saves/session, session length, engaged sessions/user
- Secondary: hide rate, diversity (unique topics shown)
- North star: 7-day and 28-day retention
Notification Metrics
Online:
- Open rate (but condition on whether user would have opened app anyway)
- Incremental sessions vs. long-term holdout (1-2% never get algorithmic pushes)
- Opt-out rate, notification settings changes, app uninstalls
Guardrail: Never ship improvements to open rate if opt-outs increase
Preventing Feedback Loops
Critical safeguards against model collapse:
- Explicit negative signals in loss: Model hide/dismiss actions as first-class prediction tasks with high weights
- Long-term holdout groups: Maintain 1-2% of users in algorithmic control to detect slow degradation that short A/B tests miss
- Inverse propensity weighting: Correct for the fact that training data over-represents what the model already chose to show
- Exploration traffic: Ensures training data includes outcomes from content the model wouldn't have selected
- Direct feedback collection: Periodic prompts asking "why did we send this?" to gather explicit labels
A/B Testing Strategy
Run parallel experiments:
- Short-term (1-2 weeks): Measure engagement lift
- Long-term (4-8 weeks): Measure retention, opt-outs on a smaller cohort
- Only promote changes that win on both horizons
8. Common Pitfalls
- Optimizing notification CTR without measuring counterfactual value: High CTR might just mean you're notifying already-engaged users who would have visited anyway
- Ignoring position bias: Models learn to rank based on where items were shown, not their true relevance
- Insufficient exploration: Models collapse onto existing interests, reducing long-term satisfaction
- Notification budget violations: Sending too many pushes in aggregate causes waves of opt-outs even if individual notifications score well
- Train-serve skew: Feature definitions diverge between offline training and online serving, causing performance degradation
Summary
The core architectural principle: share retrieval and embedding infrastructure, but diverge in ranking objectives. Feed ranking optimizes for engagement within an already-opted-in session. Notification ranking must account for attention cost, incremental value over organic discovery, and long-term user trust. Both surfaces require explicit exploration mechanisms and safeguards against feedback loops, but notifications demand much more conservative exploration and stricter budget discipline.