Arrival-Time Prediction for a Ride-Hailing Platform
Machine LearningModel answerLast updated
Design a production ML system that predicts pickup and trip-duration estimates with calibrated uncertainty, covering features, models, serving, leakage control and A/B rollout.
You are building the service that tells riders, at the moment they request a ride, how long until the car arrives and how long until they reach their destination. Design the whole system, from data to rollout.
Cover the following:
- Inputs. Which data sources and features would you use? Think about the road network, GPS traces, historical and live speeds, incidents and closures, weather, local events, supply and demand, driver behavior, and device or network conditions.
- Models. Compare three options: a map-matching plus time-dependent shortest-path baseline, gradient-boosted trees, and a spatiotemporal deep model (sequence or graph based). Explain how you represent a route and how you handle errors whose spread changes with trip length, weather or congestion.
- Uncertainty. Produce a point estimate plus 50% and 90% intervals. Explain how you would obtain and calibrate them (for example quantile regression and conformal prediction).
- Architecture. Describe training and serving: feature store, streaming updates, drift detection, refresh cadence, canary releases, and latency and availability targets.
- Data integrity. How do you prevent leakage and handle censoring (post-dispatch signals, reroutes, cancellations)? How do you deal with new regions and rare events?
- Offline evaluation. Which metrics (MAE, MAPE, P50 and P90 error, 90% interval coverage, CRPS) and which slices (city, time of day, weather, surge)?
- Online evaluation. Design the A/B test, including guardrail metrics (cancellation rate, rider wait, driver idle time, interval reliability) and rollout criteria.
Finish with the main trade-offs and name the model you would ship first as an MVP.
Hints
Hint 1
Treat the two targets separately: the pickup estimate depends on which driver is chosen (unknown at request time), while the trip estimate is pickup time plus travel along the planned route.
Hint 2
Use the routing engine's own estimate as a strong feature and have the learned model predict a correction (for example the log of actual over routing estimate) rather than raw duration.
Hint 3
For leakage, ask for every feature: would it be known at request time? Cancellations are censored labels, not missing ones, so decide explicitly how to treat them.
Hint 4
Calibrate intervals per stratum (city, hour bucket, weather) and monitor realized coverage online so you can recalibrate or roll back quickly.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and requirements
Split the problem into two targets:
- Pickup ETA: time for a driver to reach the rider. The driver is not yet known at request time, so either score each dispatch candidate or estimate over the nearest K available drivers.
- Trip ETA: pickup ETA plus travel time along the planned route from pickup to destination.
Assumed scale: tens of millions of trips per day, with 10-50 ETA calls per trip (app opens, fare quotes, dispatch scoring), giving on the order of 500k QPS at peak. Targets: model p99 of 50 ms or less within a ~100 ms total budget, 99.99% availability, and a fallback to the plain routing ETA if the model fails. Output: P50 plus 50% and 90% intervals (P25/P75, P05/P95), with a route ID and model version for debugging.
2. Features
| Group | Examples |
|---|---|
| Road graph | Segment length, class, speed limit, lanes, signals, turn restrictions |
| Route aggregates | Distance, turn count, highway share, segments per class |
| Historical speeds | Per segment by hour-of-week: median and variance |
| Live traffic | Segment speeds from the last 5-15 minutes, incidents, closures |
| Context | Precipitation, visibility, events, holidays |
| Marketplace | Supply/demand density per spatial cell, surge, nearby idle drivers |
| Driver (pickup) | Heading, speed, ratio to segment norm, GPS staleness |
| System | Device and network latency |
| Location | Cell embeddings, pickup-point difficulty (airports, malls) |
The routing engine's ETA is the single most valuable feature.
3. Modeling
Baseline: map matching plus time-dependent shortest path. Match GPS to segments with an HMM, estimate segment times from blended historical and live speeds, then route. It is cheap and interpretable but ignores intersection delay, pickup friction and regional bias (MAPE typically 20-25%).
Gradient-boosted trees (residual). Predict log(actual / routing_eta) from route aggregates and context. Sub-millisecond inference, robust, easy to debug. Weakness: aggregates lose segment order.
Spatiotemporal deep model. Encode the route as a sequence of segment embeddings (hashed ID, class, live speed) with a transformer or 1D-conv, or a GNN on the local graph; fuse with time, weather and cell embeddings; predict the same residual. It captures interactions (congested arterial before an on-ramp) and shares strength across segments, but costs more latency and needs careful serving (linear-attention variants, quantization).
Heteroskedasticity. Predict in log-ratio space, output quantiles (or a log-normal mean and variance), and add variance features such as historical segment speed variance and incident flags.
4. Uncertainty and calibration
- Quantile heads at 0.05, 0.25, 0.5, 0.75, 0.95 with pinball loss; enforce monotonicity by predicting positive increments.
- Conformalized quantile regression: on a recent window (say 7 days) compute scores
max(q_lo - y, y - q_hi), take the adjusted (1-alpha) quantile and widen the interval. Use Mondrian (per city x hour bucket x weather) calibration so coverage holds locally. - Adaptive conformal online: adjust alpha per city from streaming coverage to react to drift within hours.
- Goal: about 50% of actuals in [P25, P75] and about 90% in [P05, P95], with the narrowest intervals that still achieve it.
5. Architecture
- Offline: trip logs go through a point-in-time feature store (as-of joins). Retrain GBT daily and the deep model weekly; recompute conformal offsets hourly.
- Streaming: GPS to Kafka to a stream processor doing map matching, updating live segment speeds every 1-2 minutes into a low-latency online store (Redis or Cassandra). Incidents and marketplace density follow the same path.
- Serving: routing service produces route and baseline ETA, features are fetched (segment-level cache), model emits quantiles, conformal adjustment applied, response returned. Timeout or failure returns the routing ETA with heuristic intervals.
- Monitoring: PSI on key features, prediction drift, and delayed-label metrics (bias, MAE, coverage) per city and hour. Coverage below about 85% triggers recalibration or rollback.
- Release: shadow scoring, 1% per-city canary, staged ramp, automatic rollback on error or latency SLO breach.
6. Leakage, censoring, cold start, rare events
- Point-in-time only. No post-dispatch GPS, no traffic observed after request time, and driver state as of the request.
- Reroutes. Features describe the route planned at request time; the label is actual elapsed time. Never recompute features on the driven route. Keep traffic-driven reroutes; drop driver-initiated anomalies (fuel stop, multi-stop).
- Cancellations. They censor the pickup label (true time exceeds elapsed time). Use a censoring-aware loss (survival or Tobit-style) or exclude and reweight with inverse-probability weights. Dropping them naively biases ETAs optimistic.
- Cold-start regions. Rely on the routing ETA plus a global model with region-agnostic features, borrow from similar cities via embeddings, and use wide conformal intervals until enough data accumulates.
- Rare events (storms, concerts, closures): event and incident features, fast adaptive conformal widening, and a fall back toward the baseline when features are out of distribution.
7. Offline evaluation
Metrics: MAE and MAPE (watch MAPE on short trips), P50 and P90 absolute error, bias, 90% interval coverage and width, pinball loss, and CRPS for the whole distribution. Slice by city, time of day, weather, surge, trip-length bucket and new versus mature region. Use time-based splits, never random ones, and check that gains are not confined to easy slices.
8. Online evaluation
Randomize at the rider or request level (or by city-time for marketplace effects, to limit interference). Primary: realized ETA error and rider-facing accuracy. Guardrails: cancellation rate, pickup wait, driver idle time, conversion, interval coverage and latency. Roll out when error improves significantly, no guardrail regresses beyond a preset threshold, coverage stays within about 2 points of target, and latency SLOs hold in every major city. Watch for feedback loops: shown ETAs influence cancellations and dispatch.
9. Trade-offs and MVP
Deep models give the best accuracy on complex routes but cost latency, infrastructure and debuggability. GBTs capture most of the gain cheaply. Wider intervals are safer but less useful.
MVP: routing ETA plus a GBT residual model with quantile outputs, wrapped in per-stratum conformal calibration, backed by the routing-ETA fallback. Add the sequence model later, only where the slice analysis shows aggregate features are the bottleneck.
Common mistakes: leaking post-request information, ignoring censored cancellations, reporting only global coverage, evaluating with random splits, and skipping the fallback path.