End-to-End Design of a Food Delivery Recommendation Engine
Machine LearningModel answerLast updated
Design a personalized restaurant ranking system for a food-ordering app, covering retrieval, ranking, cold start, implicit feedback, and offline/online evaluation.
Scenario
You are a machine learning engineer at a large food-ordering platform. The product team wants to improve the home feed by surfacing restaurants each user is most likely to order from, rather than showing a generic popularity-sorted list.
Your Task
Walk through the full design of a restaurant recommendation system, from raw data to a served feed. Your answer should address:
- Problem framing — What is the right objective to optimize? How does it differ from a pure content-discovery product like a social feed?
- Data and features — What signals are available? How do you handle implicit feedback (impressions, clicks, orders) and noisy labels?
- Model architecture — Compare and contrast collaborative filtering, content-based approaches, and hybrid retrieval-plus-ranking funnels. Which would you recommend and why?
- Cold start — How do you handle a brand-new restaurant with no order history? A brand-new user with no activity?
- Offline evaluation — Which metrics matter, and what are the common mistakes when setting up the evaluation protocol?
- Online evaluation — How do you run an A/B test for this system? What guardrails would you put in place given the two-sided marketplace dynamic?
You are expected to discuss trade-offs, give rough numbers where relevant, and flag common failure modes at each stage.
Hints
Hint 1
The objective matters more than the model. A food app cares about completed orders and long-term retention, not raw clicks — start by anchoring every design decision to that north star, and explain why CTR alone is a misleading proxy.
Hint 2
A multi-stage funnel (eligibility filter → candidate retrieval → ranking → re-ranking) is standard here. For retrieval, think about why a two-tower model trained on in-radius negatives outperforms one trained on random global negatives — the hardness of the negative examples is critical.
Hint 3
Cold start has two distinct sub-problems that need different solutions: new restaurants benefit from content features and exploration budgets with a bandit policy, while new users benefit from context-only signals and rapid in-session adaptation via a sequence model over real-time clicks.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify the Objective Before Touching Any Model
The single most important thing to establish is what you are actually optimizing. A food-delivery app is not a content feed. The user's goal is a satisfying meal delivered on time, not entertainment. That changes everything:
- North star metric: completed orders per active user, weighted by retention signals (reorder rate, rating given). Clicks are a means, not an end.
- Hard constraints that filter candidates first: the restaurant must be open, within delivery radius, and actively accepting orders. No model score overrides these.
- Context dominates: breakfast, lunch, late-night, weekday vs. weekend, and location (home vs. office) are among the strongest signals. A recommendation system that ignores context will surface sushi at 8 a.m.
- Two-sided marketplace: routing all traffic to a handful of top-ranked restaurants degrades ETA for everyone. Supply-side health is a constraint, not an afterthought.
State assumed scale explicitly: ~50M DAU, ~500K restaurants, ~1–3K eligible per request after geo filter, peak ~50K QPS at mealtimes, latency budget ~150ms p99.
2. Multi-Stage Funnel
A single model scoring 500K restaurants per request is infeasible. The standard solution is a funnel:
Stage 1 — Eligibility filter (~2K candidates) Geo index (geohash or S2 cells), open-now check, capacity/ETA check. Fast, deterministic, non-ML.
Stage 2 — Candidate retrieval (~300–500 candidates) Take a union from multiple sources:
- Two-tower ANN lookup (described below)
- Reorder candidates from user history (a very strong baseline — habitual reorders are a large fraction of orders)
- Item-item collaborative filtering ("users who order X also order Y")
- Exploration slots: new restaurants, locally trending
Stage 3 — Ranking (~50 candidates → scored list)
A multi-task model predicting p(click), p(order | click), and optionally expected reorder probability. Combine into a single score, e.g. score = p(order) × value_weight. Value weight can incorporate basket size or margin but should be weighted carefully to avoid pushing users toward expensive options they did not want.
Stage 4 — Re-ranking (policy layer)
- Cuisine diversity: avoid ten consecutive pizza places
- ETA and capacity penalties
- Fatigue dampening for repeatedly impressed but unclicked restaurants
- Ad and promotion slot injection
3. Model Choices and Trade-offs
Collaborative filtering (matrix factorization / ALS) Captures latent taste similarity from the order matrix. Works well at scale, but fails on cold items and users, ignores context, and can amplify popularity bias toward a few dominant restaurants.
Content-based Represents restaurants via cuisine tags, menu-text embeddings, price level, and dietary attributes; users via aggregated affinities. Solves cold start and is interpretable. Under-personalizes and tends toward over-specialization (keeps recommending the same cuisine the user already knows).
Hybrid two-tower (recommended for retrieval)
- User tower: user ID embedding + sequence embedding over recent orders + context (time, location, session activity)
- Restaurant tower: restaurant ID embedding + content features (cuisine, menu text, price, photos)
- The ID embeddings act as collaborative filtering; content features keep cold restaurants representable from day one
- Train with sampled-softmax on (user, ordered restaurant) pairs. Critical detail: sample negatives from the in-radius pool, not globally. A restaurant 50 km away is a trivially easy negative and teaches the model nothing useful.
Ranker Start with GBDT (LightGBM) on hand-crafted features — it is fast, interpretable, and strong. Key features: distance, ETA, user–cuisine affinity score, historical CTR and conversion (smoothed), time-of-day match, reorder count. Upgrade to a DNN (DCN or DLRM style) with embedding features and order-sequence context when data volume justifies it. Use multi-task heads so the sparse order signal is regularized by the denser click signal.
4. Implicit Feedback
User behavior is messy:
- Label hierarchy: order > add-to-cart > menu view > click > impression with no engagement
- Negatives: use impressed-but-skipped items, not unseen items. An unseen restaurant is not a dislike; it may simply never have been shown.
- Position bias: log the served position. Train with position as a feature and zero it out at serving time, or use inverse propensity weighting. Not correcting for this causes the model to learn that position 1 is inherently good.
- Noise: filter accidental clicks (sub-1-second dwells), treat cancellations as soft negatives, and treat no reorder after a completed order as a weak negative signal.
5. Cold Start
New restaurants
- The content side of the retrieval tower provides a starting embedding from day one.
- Initialize the ID embedding as the centroid of similar restaurants in the same city.
- Apply Bayesian-smoothed ratings (Wilson score or a hierarchical prior) so that two five-star reviews do not outrank a restaurant with 10,000 reviews.
- Reserve a small exploration budget — a few guaranteed impression slots per new restaurant, using Thompson sampling on conversion rate as the bandit policy. Decay the boost as evidence accumulates (roughly after 1–2K impressions).
New users
- At signup, use context only: location, time of day, device, acquisition channel.
- Fall back to locally popular restaurants diversified across cuisine categories.
- Optional onboarding (pick 3 cuisines, flag dietary restrictions) bootstraps the content-based profile immediately.
- In-session adaptation: feed real-time clicks into the user tower. After 2–3 clicks, a session-sequence model can meaningfully shift recommendations without waiting for an order.
6. Offline Evaluation
Common mistakes first:
- Do not split randomly. Train on weeks 1–N, test on week N+1. Random splits leak future data into training and produce optimistic numbers that do not hold in production.
- Restrict the candidate set to what was eligible at test time. Scoring a restaurant that was closed or out of range at the test timestamp is unrealistic.
Metrics to track:
- Retrieval: Recall@K — did the stage-2 funnel include the restaurant the user actually ordered?
- Ranking: AUC and log loss per task head; NDCG@K and MRR using orders as relevance; calibration (critical when combining scores from multiple heads).
- Beyond-accuracy: catalog coverage, cuisine diversity per feed, novelty rate (share of non-reorder recommendations), restaurant exposure Gini coefficient. A system that converges all demand onto the top 5% of restaurants is a marketplace risk.
- Sliced evaluation: new users, new restaurants, specific cities, and meal-time buckets. Aggregate metrics can hide regressions on important sub-populations.
7. Online Evaluation and Guardrails
Run a standard randomized A/B test:
- Primary metric: order rate per session (not CTR).
- Secondary metrics: reorder rate at 30 days, mean ETA, restaurant-side fulfillment rate, and revenue per user.
- Guardrails: flag if new restaurant impression share drops (exploration regression), if ETA degrades (sending too much traffic to capacity-constrained kitchens), or if cancellation rate rises (quality regression).
- Duration: run for at least two full week cycles to capture weekday/weekend effects and avoid novelty bias inflating early results.
- Common mistake: launching on a metric lift in clicks without checking whether order conversion moved. Clicks and orders can diverge if the model learns to surface attractive-looking but slow or expensive restaurants.