Ch.24: System Design: Why the Closest Driver Is Wrong

Outline

Transcript

0:00 The app says a driver is 2 minutes from a rider leaving a museum. She looks up, looks back, and the car icon is gone. Was there ever a driver coming? Maybe not. That dot could be old. Even a real car nearby might need a long detour across this river. The map's 2-minute promise could be wrong twice. A product manager could reasonably ask, “Why make the rider wait when we already show a car beside her?” Before calling that car hers, check its last location report. Take a driver client that goes quiet: the redraw hides its icon, but our fictional cache keeps the old coordinate.

0:36 Uber describes GPS errors in dense streets. A dot is an observation, not a reservation. Right, the icon has a very short job description. It reports a phone's last position, yet the rider reads it as an arrival claim. I'd expect dispatch to know more than the map does. So could we draw the car before anyone has offered her a ride? Yes. The map drew a car; we have no route or match yet. A driver's Accept tap is provisional before commit. If the product labels that dot “Driver arriving,” we've promised a ride from the weakest evidence. Ah, the picture outruns the trip.

1:13 I'd rather show an honest wait than give her a driver she never had. What must happen before that label changes? That icon leaves her waiting outside the museum. Three other cars might help, but none is hers yet. Before her screen can say Driver confirmed, we need a free car, a road-time estimate, a timely yes, and an assignment both phones can read. Those are our functional requirements; miss one and she waits. And I'd worry about the non-functional requirements too: a quick answer without routing every car in the city, and no double confirmation if she retries.

1:48 Could we show a pickup estimate while her phone says Finding a driver? Yes, label it as an estimate. Finding a driver stays until a timely acceptance is committed for her request. If she taps Retry before that commit, the same request ID shows its current state. Her original search continues; there is no second dispatch request. So her wait screen stays truthful until someone actually says yes. What timestamp was on that vanished pin? Take that ghost driver as a concrete case. The map kept its riverbank coordinate after the phone went quiet.

2:21 Our index keeps an observation sequence and accuracy estimate apart from availability; the redraw updates none of them. Hang on. Would you reject a position older than, say, a minute? What if an old update arrives after a new one and looks fresh by arrival time? I'd enforce an age limit, yes; a minute isn't universal. And if report 41 arrives after 42, we keep 42 rather than make the driver jump backward. The old ghost still fails our freshness check, even if the map says “last seen.” Right, and time isn't the only problem.

2:55 Uber describes urban GPS errors; a fresh fix can still put a car on the wrong street side. A crisp icon can't make a vague position precise. You're right. My first thought was to filter on age alone, but that misses bad fresh fixes. Freshness says when the phone saw a point; accuracy says how far the car could be from it. The ghost fails freshness and drops out. Map distance can still fool us. With the ghost car gone, take a request with three candidates: Mira, 300 meters away over the river; Leo, a kilometer away on this bank; and Nia, a bit farther.

3:33 Why not route the whole city? That would spend latency and money on implausible cars. Index fresh, available positions by geographic cells. The pickup cell and neighbors give us a first shortlist; Uber's published H3 grid divides a map into hexagonal cells for that coarse search. The cell can tell me who is nearby, not who can reach the bridge entrance. A driver just outside those neighboring cells might get here sooner than one trapped inside them. So our first ring could miss the fastest road route?

4:04 Yes. A cell border doesn't know the road network. Right. Route the first shortlist. If its best pickup exceeds our rider-facing target and the request has time, widen one ring. We may still miss the citywide fastest driver. Recheck availability before offering; the index can lag. Yeah, I think Mira still wins. What are the road times? Road times reverse the order. In our fictional pickup, Mira takes 9 minutes, Leo 4, Nia 6. Mira is nearest on the map but slowest across the bridge. Leo gets the first offer.

4:39 Oh, wow. Mira is closer across the river and more than twice as slow by road. Google's route-matrix docs support traffic-aware road durations, so we ask for these few routes. Could the rider see Leo's 4-minute estimate while he decides? Yes, as a provisional forecast, never as “your driver.” If the route lookup fails, we can't substitute straight-line distance; we try another candidate or keep searching. We'd sample wider searches to see how often the first ring missed a faster pickup, while watching latency.

5:10 A prediction isn't a booking. So the fastest route only tells us whom to ask first. Leo may still disappear. With the road ranking settled, Leo gets a timed offer. His phone displays it, but the connection drops before the server hears back. Uber describes separate offer and acceptance events. Our server still needs a timely yes before it can confirm this ride. A delivery receipt isn't a yes. We've all seen a client show success while the server still had no record. The rider keeps searching. Who owns Leo's countdown?

5:43 The server owns it. In our proposed design, the deadline starts when it sends the offer, before Leo necessarily sees it. When time runs out without a response, it asks Nia; the rider's request stays open. Then I'd watch how much response time the driver actually gets: send-to-delivery delay when we can measure it, plus late Accept taps. For example, on a bad connection the offer could arrive as it expires. Leo's phone is offline; could his queued tap arrive after Nia answers? Yes. Tune that deadline against rider wait, not just by lengthening every offer.

6:18 The server can expire Leo's offer but can't erase the queued tap. His phone should show Sending acceptance until the server confirms. Both drivers may tap Accept; only one wins. That queued tap sets up a race on our rider's request. Nia accepts while her offer is live; Leo's old tap lands afterward. Could both become a match? No. Keep the request, offer, and driver claim in one transactional store. Nia's conditional write checks her live offer, this open request, and her free driver record. It assigns the rider and marks Nia busy together.

6:52 Leo's expired offer fails. Okay, that prevents two drivers on one rider. For example, what if two dispatch workers both recheck Nia while she looks free, then each sends her an offer for a different rider? If her phone sends Accept for both, where do those claims meet? At Nia's one driver record. Both workers saw free, but only one conditional transaction can mark her busy. Whichever acceptance commits first wins; the other request returns to candidate search. In our museum ride, Nia's claim won.

7:21 In production, I'd inspect that claim and both request states. That winning commit leaves one more failure path: imagine the confirmation push never reaches the rider. Her screen still shows the search; Nia's phone says confirmed. We've all hit Retry when no answer appeared. Does her retry dispatch again? No. Retry reads Nia's committed assignment for her original request; Nia's app can too. Each app reports its displayed state when connected; operators can spot a mismatch or missing report. Fresh routes can revise the pickup estimate.

7:54 “Roughly 6 minutes” isn't a deadline. A missing message isn't a missing trip. I like that the icon gets a job again: progress after the match. Let's give the rider her actual timeline. Now Nia approaches the museum. The old pin failed freshness. Cells shortlisted the three live cars; roads favored Leo, but his offer expired. Nia accepted in time, and the match store committed her assignment. Both phones read the committed assignment despite the lost push. The rider can trust Nia is hers, not that traffic will deliver her at an exact minute.

8:28 The vanished icon was never hers. Right. One current assignment is the strong guarantee in our proposed store; the pickup time is the weaker prediction. That difference is what the map had hidden. Exactly. The nearest car might win some rides. For this one, the closest pin was the wrong answer. We needed a credible report, a road route, and a committed yes. Thanks for listening to Learning Podcasts.