Arrival-Time Prediction for a Ride-Share App: End-to-End ML Design
Machine LearningModel answerLast updated
Design a machine learning system that predicts driver pickup time and trip duration, covering labels, features, models, metrics, bias, noise, serving, monitoring, and post-launch experiments.
You are a data scientist at a ride-sharing marketplace. The rider and driver apps both need to show time estimates, and you have been asked to design the prediction system behind them. There are two separate estimates:
- Pickup time: how long until the assigned driver reaches the rider.
- Trip time: how long the ride takes from pickup to drop-off.
Walk through how you would build this system from start to finish. Your answer should cover:
- Targets and labels: what exactly you predict, how you build ground truth, and how you clean it.
- Features: what is available at prediction time, including time, location, route, and live-traffic signals.
- Model choices: a baseline, a first production model, and a more advanced follow-up.
- Loss and metrics: the trade-offs between MAE, RMSE, MAPE, and quantile loss, and which you would pick for which use.
- Calibration: how you check and correct both average error and uncertainty ranges.
- Data problems:
- bias from cancelled rides,
- sudden traffic disruptions,
- noisy GPS and map-matching errors,
- sparse data in new or rarely visited areas.
- Serving: latency limits, fallbacks, retraining cadence, and monitoring.
- Experimentation: how you would test the system after launch and which guardrails you would watch.
State any assumptions you make about scale and product behavior.
Hints
Hint 1
Treat pickup and trip estimates as separate products with different consumers and different costs of being wrong. Then ask whether the model should predict raw duration or a correction on top of a routing engine's estimate.
Hint 2
A ride that was cancelled still tells you something: the true wait was at least as long as the time the rider waited. Think about censoring, and about the fact that dispatch only observes drivers who were chosen.
Hint 3
For metrics, ask which error each one punishes or hides (short trips for MAPE, bad labels for RMSE, asymmetry for quantile loss). For calibration, remember that a good global average can hide large errors in specific places such as airports.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify the problem and scale
Pickup and trip estimates serve different purposes, so I would scope them separately and share infrastructure where it helps.
- Pickup estimate: from dispatch until the driver arrives. It is shown to riders and used by dispatch to rank candidate drivers.
- Trip estimate: from pickup to drop-off. It is shown to both sides and feeds upfront pricing and shared-ride matching.
Assumptions: roughly 20M trips per day, but far more estimate calls than trips (re-estimates, app opens, scoring 10-30 candidate drivers per request), so peak load of 100k-500k predictions per second. The model gets a p99 budget of roughly 20-50 ms because the routing engine uses most of the end-to-end latency.
Errors are asymmetric. A late driver raises cancellations and hurts trust. An early driver just waits. Pricing needs an unbiased mean, while the rider display benefits from a slightly conservative quantile.
2. Targets and labels
- Pickup label: arrival time minus dispatch time. Define arrival from the cleaned GPS track (within about 50 m of the pickup point and nearly stationary), and cross-check it against the driver's "arrived" tap, which is often early or late.
- Trip label: drop-off time minus pickup time, validated against the map-matched trajectory.
- Cleaning: drop or repair impossible speeds, long GPS gaps, and detours such as a driver going offline mid-trip.
- Residual target: predict a correction to the routing engine's estimate, either
y - eta_routeorlog(y / eta_route). The route engine handles distance and road structure; the model learns intersection delays, pickup friction, and live conditions. This generalizes better and degrades gracefully, because the fallback is the routing estimate itself.
3. Features (only what is known at request time)
- Route: routing estimate, distance, turns, signals, highway fraction, road classes.
- Live traffic: route-weighted current speed versus historical speed, sample counts and freshness of those speeds, incident flags.
- Time: hour-of-week, holidays, events, weather.
- Geography: H3 cells at several resolutions as learned embeddings, plus place types (airport, stadium, campus, large complexes).
- Pickup-specific: driver heading relative to the pickup, whether a U-turn is needed, side of street, driver state (idle versus finishing a trip), local supply and demand.
- Leakage guard: never use the route actually driven or traffic observed after the request.
4. Models
| Stage | Model | Reason |
|---|---|---|
| Baseline | Routing engine with segment speeds | Fast, interpretable, works everywhere |
| V1 | Gradient-boosted trees on the residual, with quantile objectives | Strong on tabular data, cheap inference |
| V2 | Neural net with geo/time embeddings and multi-head output (mean, p10/p50/p90) | Learns interactions, shares strength across cities, can share a backbone between pickup and trip tasks |
Ship V1 first, because it delivers most of the gain with simple serving. Move to V2 when embeddings and shared training measurably beat it.
5. Loss and metrics
- MAE: targets the median, robust to bad labels, easy to explain ("off by 1.2 min").
- RMSE: targets the mean and punishes large misses, but is sensitive to corrupted labels. Use it where pricing needs unbiased means.
- MAPE: matches perceived relative error but explodes on short pickups (2 min off on a 2 min estimate is 100%) and pushes predictions low. Restrict it to trips above about 3 minutes or use log-ratio error.
- Pinball (quantile) loss: gives p50 for display and p90 for buffers, and encodes asymmetry. If lateness costs roughly twice earliness, display around the p67-p70 quantile.
My recommendation is multi-quantile heads, with an asymmetric display quantile. Report MAE, bias, and the share of trips with absolute error above 2 minutes, sliced by city, hour, trip length, and place type.
6. Calibration
- Mean calibration: bin by predicted value and plot mean actual versus predicted, per city, hour, and length bucket. A near-zero global bias can hide a +20% error at airports.
- Quantile calibration: p90 should cover about 90% of outcomes in every slice.
- Fixes: isotonic or conformal recalibration per segment, plus an online correction (EWMA of recent residuals per region, refreshed every few minutes).
7. Data problems
Cancellation bias. Completed trips over-represent fast pickups, so training only on them underestimates waits.
- Treat cancellations as right-censored: the true wait exceeded the time the rider waited. Use a censored or survival loss, or a discrete-time hazard model.
- Use post-cancel GPS to reconstruct how long the driver would have needed.
- Correct dispatch selection (winner's curse: chosen drivers had the lowest predicted time). Add small randomized exploration or use inverse propensity weights.
- Remember the displayed estimate changes rider behavior, so judge accuracy together with cancel rate.
Traffic shocks (accidents, storms, stadium exits). Use live segment speeds with freshness features, regional online residual correction, incident feeds, and anomaly detection that widens intervals when recent error spikes. Backtest on historical shock days.
GPS and map-matching noise (urban canyons, tunnels, stacked roads, ping gaps). Use HMM-based map matching with confidence scores, filter low-accuracy pings, drop low-confidence trips from labels, and use robust losses.
Geographic cold start. Fall back to the routing estimate plus a coarse-cell or city-level correction. Use hierarchical embeddings so sparse cells borrow from parents, and widen intervals where data is thin.
8. Serving, retraining, monitoring
- Precompute heavy features (H3 embeddings, historical speeds) and cache live speeds with short TTLs.
- Keep a latency fallback: if the model times out, return the routing estimate with
fallback=true. - Retrain weekly (daily for the online bias layer), and log every prediction with model version and feature hash for label joins.
- Monitor feature drift, freshness, residual bias and coverage by slice, and cancellation rate, with alerts on sustained deviations.
9. Experimentation
Randomize at the rider or request level for display changes. Because dispatch and pricing interact across users, use geo-time switchback tests when the model drives matching. Primary metrics: pickup MAE and bias, cancel rate, and conversion. Guardrails: driver idle time, completed trips, p99 latency, and fairness across neighborhoods. Run long enough to cover weekly cycles, and check for interference between treatment and control.
Common mistakes
- Optimizing one global metric and missing slice-level bias.
- Using MAPE on short pickups.
- Training only on completed trips.
- Leaking post-request information.
- Skipping a fallback path.