NelworksNelworks

Tech / Season 1 / EP04

Uber Dispatch

Tweet coming soon
Shez

$70? For a three-mile ride?

Shez

I just want to go home!

Shez

Whoa. That was fast. Was he hiding in the bushes?

Kurumi

Get in loser. You're soaked in rain and somehow you still smell like alcohol.

Shez

Kurumi? Never knew you had a side hustle? I paid 3x surge for this!

Kurumi

Buckle up and move.

Shez

Wait... I know this. We did this with Google Maps. The S2 thing. The squares.

Shez

But these aren't squares. They're... hexagons?

Kurumi

Your head is pretty clear for a drunk. Yes. Google uses Squares (S2). Uber uses Hexagons (**H3**).

Shez

Why?

Kurumi

Because squares are geometrically unfair.

Shez

Unfair? It's just a shape.

Kurumi

Look at the center square. To go to the neighbor on the **Right**, it's 1 unit of distance.

Kurumi

To go to the neighbor on the **Diagonal**, it's 1.4 units.

Kurumi

If I want to search 'all drivers within 1 mile', a square grid is messy. The corners are further away than the sides.

Kurumi

Now look at the Hexagon. It has 6 neighbors.

Kurumi

Every single neighbor is the exact same distance from the center.

Kurumi

It's perfect radial symmetry. When the server asks 'Find cars near Shez', it just grabs the 6 surrounding rings. The math is simple.

Shez

So... hexagons are the bestagons?

Kurumi

Yeah. It makes the database search insanely fast. That's why I appeared in 4 seconds.

Shez

Okay, the math is great. But explain the $70. And why is the hexagon red?

Kurumi

Surge pricing. But the Hexagons save you from 'The Cliff'.

Shez

The cliff?

Kurumi

Imagine Surge Pricing on squares. Square A is $10. Square B is $50.

Kurumi

If you cross the street, the price jumps 500%. It feels broken. Users hate it.

Kurumi

Hexagons allow for **Gradient Smoothing**.

Kurumi

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.

Shez

So I paid $70 because I'm in the dark red zone...

Shez

But wait. When I tapped the button... there were like 5 cars on the screen. Why did *you* get me?

Shez

There should be a Prius right in front of me.

Kurumi

You think the car on the screen is real?

Shez

It's not?

Kurumi

The 'Ghost Cars' are mostly accurate, but the matching isn't 'First Come First Serve'.

Kurumi

It's **Batched Matching**.

Kurumi

When you tapped, Uber didn't match you instantly. It waited.

Shez

It waited?

Kurumi

For about 2 seconds. It collected everyone's request in this neighborhood.

Kurumi

If the Prius picked you up, maybe the guy down the street would have to wait 10 minutes for me.

Kurumi

But if *I* pick you up, and the Prius picks *him* up, the average wait time is 3 minutes for both.

Kurumi

The algorithm solves for the **Global Good**, not an individual user's instant gratification.

Shez

Okay. So the driver is assigned. But how does the driver... *queue*?

Shez

Sometimes my driver already has a passenger. How does he know to come to me next?

Kurumi

That is the **State Machine**.

Kurumi

While a driver is `[On Trip]`, the system is already looking at his destination.

Kurumi

It calculates where he *will be* in 5 minutes. It puts a 'Virtual Driver' at that drop-off point.

Kurumi

It matched you with me before I even finished my last ride.

Shez

Wait. I'm drunk. Where is my card?

Kurumi

Stop panicking. You don't need the card.

Shez

But I have to pay you!

Kurumi

You already did. Or rather, the code will.

Kurumi

The payment is completely decoupled from the ride.

Kurumi

When I swipe this, it sends a `Trip_Ended` event to the server.

Kurumi

The server calculates time + distance + surge. Then it talks to Stripe or Braintree.

Kurumi

It happens in the background. You could be asleep. You could be dead. You still pay.

Shez

Thanks. I'll rate you 5 stars.

Kurumi

Even after calling you a loser before you got in the car?

Shez

Right. 1 star then.