KatInterview

Delivery Time Estimation: Full ML System Design

Machine LearningModel answer
HardModel answerMachine Learningeta-predictionquantile-regressionfeature-engineering

Last updated

Design an end-to-end ML system to predict food delivery duration, covering features, leakage, modeling, calibration, cost-sensitive decisions, fairness, and production deployment.

Delivery Time Estimation: Full ML System Design

A food delivery platform wants to show customers an accurate estimated arrival time the moment they place an order. You have access to a historical dataset of completed orders with order-level, restaurant-level, and courier-level features.

Work through the following seven areas. For each one, be specific: name features, name metrics, write formulas where they add clarity, and call out trade-offs.


A) Target definition and feature design

Define the prediction target precisely, including what population you train on, how you handle outliers, and exactly when the prediction is made. Then list at least 10 features across at least three groups (demand, supply, network/logistics). For each feature, explain why it is predictive and confirm it is available at prediction time.

B) Data leakage and time-based validation

Identify at least five realistic leakage sources in this problem. Propose a time-based train/validation/test split with concrete date ranges and explain why a random split would be wrong. Describe a rolling-origin cross-validation strategy inside the training window and explain how you would handle training data from other cities or markets.

C) Modeling choices

Compare at least three model variants that differ in loss function (e.g., MSE, Huber, MAE, pinball). Explain when you would output a single point estimate versus a full predictive distribution, and what that buys you. List at least three feature interactions you would engineer explicitly and three regularization hyperparameters you would tune and why.

D) Evaluation and calibration

Define the metrics you would report on the held-out test week. Beyond point-estimate accuracy, explain how you would evaluate and visualize quantile calibration. Define calibration error formally and describe how you would fix miscalibration post-hoc without retraining.

E) Cost-sensitive decision-making

The platform incurs a cost when the quoted ETA is too short (late delivery) and a different cost when it is too long (customer under-orders or cancels). Show mathematically how to pick the optimal ETA to quote given asymmetric costs. Then extend the same logic to the dispatch decision: when should a courier be sent to the restaurant to minimize the sum of idle-wait cost and cold-food cost?

F) Explainability and fairness

Describe how you would use feature attribution (e.g., SHAP) to audit the model. Then outline at least two fairness checks you would run—across geography, cuisine type, or courier vehicle type—and name at least two mitigation strategies if you find disparity.

G) Production system

Sketch the production architecture: feature store design, inference latency requirements, retraining cadence, and how you would detect feature or label drift. Describe how you would run an online experiment to confirm that offline metric gains translate to real-world improvement, including what guardrail metrics you would monitor.


What a strong answer looks like: structured responses to all seven parts, specific metric names and formulas, honest discussion of trade-offs at each stage, and a clear thread connecting modeling choices to downstream business outcomes.

Hints

Hint 1

For target definition, think carefully about *when* the prediction must be made — the legal feature set depends entirely on that timestamp. Decomposing the journey into legs (prep → courier travel to restaurant → wait → last-mile) helps both accuracy and interpretability.

Hint 2

Leakage in time-series problems often hides in aggregate features: a 30-day rolling mean of restaurant prep time is leaky if it was computed using data after the order's created_at. The fix is a point-in-time join, not just a train/test split.

Hint 3

The newsvendor formula connects your quantile model directly to the quoting decision: if late-delivery cost is c_late and over-quoting cost is c_early, the optimal quoted ETA is the F⁻¹(c_late / (c_late + c_early)) quantile of your predicted distribution. You do not need to retrain when costs change.