Ranking Pipelines for Location Suggestions and Push Alerts
Machine LearningModel answerLast updated
Design two ML ranking systems: one that suggests nearby places to a moving mobile user, and one that decides which push notifications to send, order, or suppress.
Answer both of the following design prompts as you would in a whole-system ML design discussion. For each one, state your assumptions, sketch the architecture, and justify the trade-offs.
Prompt A: Suggesting places near a mobile user
A smartphone app should suggest relevant places (restaurants, shops, points of interest) around the user. The user's position can change while the app is open, so the suggestions must follow them.
Cover:
- Problem definition and the success objective
- Candidate generation and ranking
- Features and training data (labels, biases)
- Online serving, latency budget, and data freshness
- Cold start for new places, users, and regions
- How to handle a user who is moving
- Offline and online evaluation
Prompt B: Ranking push notifications from many sources
Several producers (product announcements, friend activity, advertiser messages) emit candidate notifications for each user. The system must decide which are eligible, which should go out and in what order, and which should be suppressed.
Cover:
- The objective function and how it accounts for long-term harm
- Eligibility rules
- De-duplication and aggregation
- User fatigue and send budgets
- Multi-objective ranking, model design, and training labels
- Serving architecture
- Evaluation
State any scale numbers you assume (users, QPS, latency targets).
Hints
Hint 1
Start by turning each product goal into a measurable objective. Raw clicks or opens are easy to game and can hurt users in the long run, so think about downstream actions and negative signals.
Hint 2
For the moving-user case, think about what should be predicted (future position, not just current), when a refresh is worth its cost, and how to keep the visible list from jumping around.
Hint 3
For notifications, separate cheap deterministic gates (consent, quiet hours, TTL, caps) from the learned model, and score the incremental value of sending versus not sending, with a penalty for dismissals and opt-outs.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Shared framing
Both problems follow the same pattern: define a measurable objective, build a funnel (cheap filtering, then retrieval, then a heavier ranker, then re-ranking), and watch for feedback loops and long-term harm. I would spend the first few minutes on clarifying questions, then walk the funnel, and save time for deep dives.
Part A: Nearby place suggestions
Assumptions
- Pull-style feed that refreshes as the user moves.
- About 500M DAU, roughly 3 sessions a day, about 50K peak QPS, about 200M places.
- Under 200 ms end to end, with about 100 ms for ranking.
- Opening hours and closures fresh within minutes; location fresh within seconds.
Objective
Maximize meaningful engagement: a tap followed by a real action (directions, call, save, or an inferred visit). Clicks alone reward attractive photos over useful places.
Architecture
- Location service. The client sends throttled updates (for example every 30 s or 100 m). The service smooths GPS noise and emits a current and a predicted position.
- Candidate generation (about 1,000 places, under 30 ms):
- Geo index (S2 or H3 cells): the user's cell plus neighbors, with radius adapted to density and travel mode.
- Personalized retrieval: a two-tower user/place embedding model with ANN search filtered by region or cell.
- Popular-in-area and trending places.
- Hard filters: closed, dismissed, unsafe.
- Ranking (1,000 down to about 50). A GBDT or multi-task DNN predicts P(tap), P(action | tap), and P(visit). Combine, for example:
score = P(tap)·(w1 + w2·P(action|tap) + w3·P(visit)) − w4·travel_cost - Re-ranking. Category diversity, business rules, and a small exploration slot.
Features
- Geo-temporal: travel-time ETA (better than straight-line distance), open-now, hour, weekday, weather.
- Place: rating, review count, live busyness, price, category embedding.
- User: category affinities, price fit, visit history, tourist versus local (distance from home cell).
- Context: speed, heading, transport mode, recent queries.
- Cross features: user-category affinity times place popularity at this hour.
Moving users
- Predict, don't just locate. A light trajectory model (for example a GRU over recent points, speed, and heading) predicts position at +5 and +15 minutes. Retrieve along the predicted corridor and compute ETA from the projected position, so a driver at 60 km/h is not shown places already behind them.
- Refresh policy. Re-query only when the user leaves the cell or crosses a distance threshold, not on every GPS tick. Cache the candidate set and re-score locally between refreshes.
- Stability. Penalize reordering items already on screen to avoid UI churn.
Training data
- Positives: taps and actions; strongest are visits inferred from dwell time (with consent). Negatives: impressions without engagement.
- Position bias: include position as a training feature and fix it at serving, or use inverse propensity weighting.
- Distance confounding: closer places get more exposure and look better than they are; include distance explicitly and consider propensity correction.
Cold start
- New places: content features, priors from similar places in the same cell, and an exploration boost (for example Thompson sampling).
- New users: context and area popularity, plus onboarding signals.
- New regions: transfer category-level models from similar cities.
Evaluation
- Offline: NDCG and recall@K, sliced by geo-density bucket, with visit-weighted labels.
- Online A/B: visits per session, action rate, 7-day retention.
- Guardrails: latency, closed-place complaints, concentration on a few merchants.
Part B: Notification ranking
Objective
Maximizing opens leads to spam, disabled notifications, and churn. Optimize the incremental long-term value of sending versus not sending:
value(n) = P(open|send)·V_open + P(downstream action) − λ·P(dismiss/disable/unsub) − fatigue_cost(user)
Send only if value(n) exceeds a per-user threshold, or solve a constrained optimization under a daily budget. Emphasize incrementality: friend activity the user would see anyway has low lift.
Pipeline
- Ingestion. Producers publish candidates to a queue (for example Kafka) with type, priority, TTL, and dedup key.
- Eligibility (cheap, pre-model). Per-channel opt-in, quiet hours in local time, legal and consent rules (especially ads), integrity checks, TTL expiry, per-source rate caps. Transactional and security messages (such as 2FA) bypass ranking.
- De-duplication and aggregation. Exact match on dedup key, near-duplicate detection via content embeddings, and aggregation ("Alice and 4 others liked your post") using a short buffer window for aggregatable types.
- Scoring. A multi-task model with a shared bottom and separate heads (for example MMoE) predicting P(open), P(downstream engagement), P(dismiss), and P(disable). Inputs include user history by notification type, recency of last sends, source and content features, relationship strength for social items, time of day, and device state.
- Selection and ordering. Combine head outputs into
value(n), apply thresholds and budgets, enforce per-source and per-type diversity, and choose send time (immediate versus deferred to the user's active window).
Fatigue and budgets
Track notifications sent in rolling windows, apply per-user frequency caps, and make the fatigue cost increase with recent volume. Advertiser content should compete under a stricter budget than organic social content to protect trust.
Labels
- Positive: open and downstream action within a window.
- Negative: ignored, dismissed, disabled.
- Beware selection bias: you only observe outcomes for notifications that were sent. Reserve a small randomized exploration slice, and use it for unbiased training and for estimating uplift.
Serving
Two paths: a real-time path for event-driven items (friend activity) with a tight latency budget and cached user features, and a batch or scheduled path for announcements and digests. Use a feature store for user history, with idempotent sends and a final policy check just before delivery.
Evaluation
- Offline: AUC and calibration per head, uplift estimates from the exploration slice.
- Online A/B with a holdout: session and retention impact, not just open rate.
- Guardrails: opt-out and uninstall rates, notification-disable rate, complaints, per-source fairness.
Common mistakes
- Optimizing clicks or opens instead of downstream value and negative signals.
- Using straight-line distance and ignoring where a moving user will be.
- Refreshing on every location update, causing cost and UI jitter.
- Ignoring position, distance, and selection bias in training data.
- Putting hard legal and consent rules inside the model instead of enforcing them as gates.
- Treating all notification sources equally, so ads crowd out personal content.