Build a Live-Now Highlights Feed for a Streaming Marketplace
System DesignModel answerLast updated
Design the ML system around an existing scoring model to rank currently active livestreams in a shopping app, covering signals, retrieval, rules, serving, and verifying a stream is still on air.
You are building the "Hot Right Now" row for a marketplace where sellers sell products over live video. The row should show each user the live shows most worth joining at this moment.
A relevance model already exists. You can call it as an internal service with a user, a stream, and request context, and it returns a score. You do not need to design or train it. Design everything around it.
Cover the following in your answer:
- The product objective and how you would measure success, including guardrail metrics.
- The events and features you would capture (stream-level, seller-level, user-level).
- How you would produce the set of candidate streams for each request.
- How you would merge hard rules, fast-moving live signals, and the model score into a final ordering.
- The online and offline architecture, including how data flows between them.
- Targets for latency, data freshness, and scale, with rough numbers.
- How you keep out streams that are outdated, low quality, spammy, or already finished.
- How you would run experiments, monitor the system, and degrade gracefully on failure.
Follow-up: How do you guarantee that a stream appearing in the feed is really still live when the user sees and taps it?
Hints
Hint 1
Start by estimating the size of the inventory. If only thousands of streams are live at once, retrieval is cheap and the real difficulty lies elsewhere. Think about what that implies for your design.
Hint 2
Do not optimize raw viewer counts alone. Think about feedback loops, fake traffic, and small sellers, and pick a primary metric tied to purchases plus guardrails for dead taps, reports, and exposure concentration.
Hint 3
For the follow-up, think in layers: an authoritative live-state store fed by heartbeats and explicit end events, a filter at serve time, a client-side check on tap, and a push or short polling mechanism to remove streams that end while the feed is on screen.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and assumptions
I would state assumptions up front so the numbers drive the design:
| Quantity | Assumption |
|---|---|
| Daily active users | ~5M |
| Peak feed requests | ~30k QPS |
| Concurrent live streams | 10k to 20k |
| Stream starts plus ends | ~500 per minute |
| Engagement events | ~200k per second at peak |
| Feed latency | p99 under 200 ms, ranking budget about 80 ms |
| Trend feature freshness | 30 to 60 seconds |
| Ended stream removal | within about 5 seconds |
The key observation is that the inventory is small but changes constantly. Scoring 20k items is cheap, so the hard parts are freshness, correctness, and abuse resistance, not retrieval at scale.
2. Objective and metrics
Goal: get buyers into shows where they will engage and purchase, while giving newer sellers enough exposure to grow.
- Primary: purchases or GMV per feed session (or bids/purchases per impression as a proxy).
- Secondary: feed-to-stream click-through, watch time beyond 30 s, follows, next-day return.
- Guardrails: dead-tap rate (target below 0.1%), reports and refunds per impression, exposure concentration across sellers (for example a Gini coefficient), new-seller impression share, and feed latency.
Optimizing raw viewer counts is a common mistake. It creates a rich-get-richer loop and rewards viewbotting.
3. Events and features
Events (all into Kafka):
- Client: impression, tap, watch heartbeat every ~10 s, leave, chat, bid, purchase, follow, share, report.
- Stream service: start, heartbeat, end, category, title, schedule.
- Commerce service: listings, auction open and close, remaining inventory.
Real-time stream features over 1, 5, and 15 minute windows: unique concurrent viewers and their velocity, join, chat, bid, and purchase rates, GMV per minute, average watch duration, report rate, time since start, and whether an auction is about to close. Normalize velocity against the category baseline so niche categories can still trend.
Batch features: seller rating, conversion, refund and dispute rate, account age, past stream count, shipping reliability, and user category affinities, followed sellers, price band, language, and recently seen streams (for fatigue).
4. Candidate generation
Start from the authoritative live set, not a search index that may lag. Merge several sources and dedupe into roughly 300 to 1,000 candidates:
- Global trending top ~500 using a cheap heuristic such as
log(viewers) + a*velocity + b*bid_rate, refreshed every 10 to 15 s by the streaming job. - Top streams in categories the user likes.
- Followed sellers who are live now.
- An exploration pool of new or low-exposure streams with good quality signals, sampled with a bandit.
- Scheduled streams about to start with many RSVPs.
5. Combining rules, signals, and the model
- Hard filters: drop streams that are not live, banned or under review, from sellers below a trust threshold, in blocked categories or regions, or already dismissed or blocked by the user.
- Model scoring: one batched call with user, stream, and context features, returning something like p(engage) or expected GMV.
- Blend:
final = model_score * quality_multiplier * freshness_factor + exploration_bonus. The quality multiplier penalizes high report or refund rates. The freshness factor decays as features age and gives a small lift to streams just ramping up. - Re-rank: cap one or two streams per seller, enforce category diversity, reserve slots for new sellers (for example 1 in 8), place bounded promoted slots, and demote streams the user already skipped.
Keep rules declarative and configurable so operations can change them without a deploy.
6. Architecture
Online: Client, Feed API, candidate service (Redis live set plus precomputed trending lists), batched feature fetch, model service, blender and re-ranker, final liveness check, response with a server timestamp.
Near real time: Kafka, then Flink windowed aggregates, written to a TTL'd online feature store, plus per-category trending lists every 10 to 15 s and anti-abuse signals.
Offline: logs land in the lake; daily jobs build seller and user features and backfill the online store; training data is logged impressions joined to outcomes, using features logged at serve time to avoid leakage. A shared feature store definition prevents training/serving skew.
Scaling: Feed API and ranking are stateless. The model service batches requests. Cache the global trending result for about 5 s and personalize on top, so most requests score about 200 items.
7. Stale, low-quality, spam, and ended streams
- Stale features: every feature carries a timestamp. If trend features are older than about 2 minutes, drop the trending boost and fall back to the base score.
- Spam and viewbots: count unique logged-in viewers with real heartbeats, weight by account trust, detect velocity spikes from new accounts or shared IP and device clusters, and discount flagged traffic.
- Low quality: require minimum seller trust and stream health (video bitrate, audio present), and penalize high report rates.
8. Follow-up: ensuring a stream is still live
Use defense in depth:
- Single source of truth: a stream state service tracks
live | ended, driven by ingest heartbeats every few seconds plus explicit end events. A missed-heartbeat timeout (for example 10 to 15 s) marks the stream ended even if no end event arrives. - Serve-time check: after ranking, do a batched lookup of the final ~20 stream IDs in the state store and drop any that are not live. This costs one Redis call.
- Event-driven eviction: an end event removes the stream from the live set and trending lists immediately, and invalidates caches keyed on it.
- Client push or short poll: while the feed is open, subscribe to end notifications (or poll every few seconds) and remove or grey out ended cards.
- Tap-time validation: on tap, verify liveness before navigating. If it ended, show a graceful fallback and route to the next stream or a replay.
- Measure: track dead-tap rate and end-to-removal lag as guardrails with alerts.
9. Experiments, monitoring, failure handling
- Experiments: A/B test on users, with a holdout, tracking GMV per session and guardrails. Watch for seller-side interference and novelty effects, and consider seller-level or interleaved tests for ranking changes.
- Monitoring: feature freshness, event lag in Kafka and Flink, model score distribution drift, latency percentiles, live-set size versus ingest truth, and dead-tap rate.
- Failure handling: if the model service times out, fall back to the heuristic trending list. If the feature store is down, use cached or default features. If the live-state store is unavailable, fail closed on liveness (serve fewer streams rather than possibly ended ones). Use circuit breakers and a static last-known-good feed as the final fallback.
Common mistakes
- Optimizing viewer count and ignoring bots and concentration.
- Retrieving from a lagging index instead of the live state.
- Skipping a final liveness check.
- Not logging features at serve time, causing training/serving skew.
- No fallback path when the model is slow.