NelworksNelworks
Season 1

EP04 - Uber Dispatch

How Uber matches drivers and riders. Learn about H3 hexagon indexing, surge pricing with gradient smoothing, batched matching algorithms, and event-driven payment state machines.

Tweet coming soon
$70? For a three-mile ride?
I just want to go home!
Whoa. That was fast. Was he hiding in the bushes?
Get in loser. You're soaked in rain and somehow you still smell like alcohol.
Kurumi? Never knew you had a side hustle? I paid 3x surge for this!
Buckle up and move.
Wait... I know this. We did this with Google Maps. The S2 thing. The squares.
But these aren't squares. They're... hexagons?
Your head is pretty clear for a drunk. Yes. Google uses Squares (S2). Uber uses Hexagons (**H3**).
Why?
Because squares are geometrically unfair.
Unfair? It's just a shape.
Look at the center square. To go to the neighbor on the **Right**, it's 1 unit of distance.
To go to the neighbor on the **Diagonal**, it's 1.4 units.
If I want to search 'all drivers within 1 mile', a square grid is messy. The corners are further away than the sides.
Now look at the Hexagon. It has 6 neighbors.
Every single neighbor is the exact same distance from the center.
It's perfect radial symmetry. When the server asks 'Find cars near Shez', it just grabs the 6 surrounding rings. The math is simple.
So... hexagons are the bestagons?
Yeah. It makes the database search insanely fast. That's why I appeared in 4 seconds.
Okay, the math is great. But explain the $70. And why is the hexagon red?
Surge pricing. But the Hexagons save you from 'The Cliff'.
The cliff?
Imagine Surge Pricing on squares. Square A is $10. Square B is $50.
If you cross the street, the price jumps 500%. It feels broken. Users hate it.
Hexagons allow for **Gradient Smoothing**.
The price flows like water. The expensive zone 'bleeds' into the cheap zone naturally. It keeps the drivers moving toward the demand without creating hard borders.
So I paid $70 because I'm in the dark red zone...
But wait. When I tapped the button... there were like 5 cars on the screen. Why did *you* get me?
There should be a Prius right in front of me.
You think the car on the screen is real?
It's not?
The 'Ghost Cars' are mostly accurate, but the matching isn't 'First Come First Serve'.
It's **Batched Matching**.
When you tapped, Uber didn't match you instantly. It waited.
It waited?
For about 2 seconds. It collected everyone's request in this neighborhood.
If the Prius picked you up, maybe the guy down the street would have to wait 10 minutes for me.
But if *I* pick you up, and the Prius picks *him* up, the average wait time is 3 minutes for both.
The algorithm solves for the **Global Good**, not an individual user's instant gratification.
Okay. So the driver is assigned. But how does the driver... *queue*?
Sometimes my driver already has a passenger. How does he know to come to me next?
That is the **State Machine**.
While a driver is `[On Trip]`, the system is already looking at his destination.
It calculates where he *will be* in 5 minutes. It puts a 'Virtual Driver' at that drop-off point.
It matched you with me before I even finished my last ride.
Wait. I'm drunk. Where is my card?
Stop panicking. You don't need the card.
But I have to pay you!
You already did. Or rather, the code will.
The payment is completely decoupled from the ride.
When I swipe this, it sends a `Trip_Ended` event to the server.
The server calculates time + distance + surge. Then it talks to Stripe or Braintree.
It happens in the background. You could be asleep. You could be dead. You still pay.
Thanks. I'll rate you 5 stars.
Even after calling you a loser before you got in the car?
Right. 1 star then.