You tap "Book" and a driver is on the way in seconds. Here's how the app picks that driver out of thousands, why the nearest one isn't always the best, and what happens when a driver ignores the ride or cancels.
Uber, Ola, Rapido · 18 min · 25 XP
The momentBasicYou need a cab, right now
You're outside a mall with shopping bags, and it has just started to drizzle. You open the app, check the fare, tap Book, and a few seconds later it says: Ravi is 4 minutes away. A little car icon starts crawling towards you along the map.
Thousands of other people in your city booked in that same minute, and thousands of drivers are moving around: some free, some carrying passengers, some parked at a tea stall with the app open. So how did the app pick Ravi, for you, in a few seconds? And why, on other days, does "Finding you a driver" spin for half a minute, or does a driver accept and then cancel?
Behind the screenBasicWhat happens when you tap
Behind that one tap, the app has to answer three questions, very fast:
Where is every driver right now? Each driver's phone sends a every few seconds: where it is, which way it's facing, and whether the driver is free.
Which free drivers are near you? Not everyone in the city, just the few who could reach you soon.
Which one should get your ride, and will they take it? Rank them, then ask them one at a time.
Step by step7 steps
1
YouCab app
Pickup here, drop at the airport
2
Cab appLocation service
Which free drivers are near this pickup?
3
Location serviceMatching
12 free drivers within about 2 km
4
MatchingDriver
New ride: pickup 4 min away. Accept?
5
DriverMatching
Accepted
6
MatchingCab app
Driver assigned
7
Cab appYou
Ravi is 4 minutes away
That pairing of each rider with a suitable driver is called . Let's take the three questions in turn.
Knowing where everyone is
A big city might have 40,000 drivers online at once. If each phone pings every 4 seconds, the app receives about 10,000 position updates a second from one city alone. Each update replaces the one before it: nobody needs to know where Ravi was 20 seconds ago to book a cab now. So the app keeps just the latest position of each driver, in the computer's fast working memory, , rather than writing every ping to a on disk. Reading from memory takes well under a millisecond.
Finding who is near
Here's the clever part. Even in memory, checking all 40,000 drivers for every booking would be wasteful, and in busy evenings thousands of bookings arrive each minute. So the map is cut into small tiles called , each perhaps a kilometre across, and every driver is filed under the cell they're in. When a ping shows a driver has crossed into a new cell, the app moves them to that cell's list.
To find drivers near you, the app looks only in your cell and the ring of cells around it:
That filing system is a . It works like a library sorting books by shelf: to find a cookbook, you go to the cookery shelf instead of reading every spine in the building. "Who is near me?" becomes "who is in these seven cells?", which might mean looking at 15 drivers instead of 40,000.
If those cells turn up nobody free, the app widens the search to the next ring out, and then the next. That's one reason "Finding you a driver" takes longer late at night or in quiet suburbs.
Picking one and asking
The drivers in those cells are a shortlist, not an answer. Some are carrying passengers. Some drive the wrong kind of vehicle (you asked for an auto, they have a sedan). And the ones closest on the map aren't always closest by road. So the app filters the list, asks a for each remaining driver's real driving time to you, and ranks them mostly by that.
Then it offers the ride to the top driver. The driver sees the pickup point and has a few seconds to accept. Only one driver is asked at a time, so that two drivers don't both turn up for you. If the driver accepts, both phones are told at once: the rider gets the driver's name and car, the driver gets directions to the pickup.
From then on, the driver's pings are passed straight to your phone, so you can watch the car approach. That's why the app feels live: the same pings that let it find Ravi now show you where Ravi is.
Step by stepNeha's cab from the mall, second by second
Neha has finished shopping at a big mall in Viman Nagar, Pune. It's 7:10 on a Saturday evening, and she wants a Mini cab to Pune railway station, about 8 km away. Here's her booking, step by step.
7:10:02 pm, she taps Book. The app sends her pickup point, her drop, the vehicle type (Mini) and the fare she was shown, about Rs 220. Her blue dot was wobbling near the food court, so the app suggested "Gate 2", a fixed pickup spot where cars can actually stop, and she accepted it.
7:10:03, the booking gets an ID. The matching service creates booking #5531 and marks it "searching". Everything that happens to this booking from now on is filed under that number.
7:10:03.1, find who's near. Matching works out which map cell Gate 2 sits in and asks the location service for free Minis in that cell and the six around it, about 2 km in every direction. The answer, read from memory, comes back in about a tenth of a second: 14 drivers.
Throw out the stale ones. Five of those 14 haven't pinged for more than 30 seconds. One is in a basement car park, two have weak signal, two may have just switched off. Their positions can't be trusted, so they're left out. Nine remain.
Get real driving times. The routing engine works out how long each of the nine would take to reach Gate 2, using today's traffic. The closest in a straight line is only 400 m away, but he's on the airport road on the other side of a divider and would need a U-turn 2 km away: 9 minutes. The best three are Suresh at 4 minutes, Imran at 5 and Kavita at 6.
7:10:04, offer the ride to Suresh. His phone shows the pickup, "4 min away", and a 15-second countdown. While the offer is open, Suresh is held for Neha's ride, so no other rider's booking can grab him.
7:10:19, no answer. Suresh is on a phone call and doesn't tap anything. The 15 seconds run out, the hold on him is released, and the offer moves down the list.
7:10:19, offer to Imran. He taps Accept at 7:10:25. In that same moment, matching checks that Imran is still free and changes him to "on the way to #5531". If two bookings had both tried to claim him, only the first change would have worked.
7:10:25.5, Neha sees her driver. Name, photo, car, and "5 min". Total time from tap to driver: 23 seconds, of which 15 were spent waiting for Suresh.
Step by step9 steps
1
NehaCab app
7:10:02 pm: Mini cab, mall Gate 2 to Pune station
2
Cab appMatching
7:10:03: booking #5531, fare about Rs 220
3
MatchingLocation service
7:10:03.1: free Minis in these 7 cells?
4
Location serviceMatching
7:10:03.2: 14 found, 9 with fresh pings
5
MatchingDriver Suresh
7:10:04: pickup 4 min away, 15 s to accept
6
MatchingDriver Imran
7:10:19: no reply from Suresh, so offer Imran
7
Driver ImranMatching
7:10:25: accepted
8
MatchingCab app
7:10:25.2: Imran, white hatchback, 5 min
9
Cab appNeha
7:10:25.5: car and driver on screen
The next five minutes. Imran's phone keeps pinging every 4 seconds, about 75 times before he arrives. Each ping goes to Neha's phone over a , a line that stays open so the server can send updates without being asked. Every half a minute the app also re-checks the arrival time with the routing engine; it creeps from 5 minutes to 6 as Imran hits a red light.
7:16:10, he's at Gate 2. Neha gets a , "Your driver has arrived", even though her phone is in her bag with the app closed. She tells Imran her four-digit , which proves he has the right passenger, and the trip begins. Booking #5531 changes from "driver on the way" to "on trip".
Notice how little of those 23 seconds was computing. Finding, filtering and ranking drivers took well under a second. Almost all the waiting was for a human to look at a phone. That's why the timeout on each offer matters so much, and why apps work hard to offer the ride first to a driver who's likely to say yes.
The tricky casesGoing deeperWhat if…
The simple version works on a quiet day. These are the situations that make it hard, and how the system handles each one.
The closest driver isn't the best one
A driver 300 m away might be across a divider, on a flyover, or on a one-way street pointing the wrong way. By road, they could be 10 minutes from you, while a driver 1 km away on your side of the road is 3 minutes away. If the app ranked by straight-line distance, you'd wait three times longer than you needed to.
How it’s handled
The app asks a routing engine for each shortlisted driver's real driving time, the , using the actual roads and today's traffic, and ranks by that. Because working out an ETA takes more effort than measuring a straight line, the app does it only for the dozen or so drivers on the shortlist, never for the whole city.
10 min (U-turn)3 minDriver A, 300 mDriver B, 1 kmYou
Two riders want the same driver
Two friends standing outside the same cinema book at the same moment, and the same driver, Ravi, is the best match for both. Matching handles many bookings at once on different computers, so both searches might see Ravi as free in the same instant. This is a : the result depends on whose request gets there first, and done carelessly, both riders could be told "Ravi is coming".
How it’s handled
When a ride is offered to a driver, the driver is held for that one booking for a few seconds, a kind of . The hold is placed in a single step that only works if the driver is still free, so if two bookings try at the same instant, one wins and the other fails straight away. The second rider's search skips Ravi and offers the next driver, a few seconds' difference that neither rider notices.
Held for Rider 1Rider 2Rider 1Rider 2MatchingDriver RaviNext driver
The driver doesn't answer
The driver is in an underpass with no signal, is paying at a petrol pump, or simply isn't looking at the phone. Meanwhile, the rider is staring at "Finding you a driver" and the driver is held, so no one else can offer them a ride either.
How it’s handled
Every offer has a , often 10 to 20 seconds. When it runs out, the hold is released and the offer moves to the next driver on the list. That's why finding a driver sometimes takes longer: each unanswered offer adds its full countdown. Apps also learn which drivers tend to ignore offers and try likelier ones first, and a driver who ignores many in a row may be marked as offline until they tap back in.
No reply in 15 sOffer moves onMatchingDriver ADriver B
A driver's location is out of date
A phone lost signal in a tunnel, or the driver closed the app without going offline. Its last ping is four minutes old. On the map the driver still looks free and 500 m away, but in four minutes a car can travel 2 km, or the driver may have gone home for dinner. Offering them rides wastes 15 seconds each time.
How it’s handled
Every ping doubles as a , a small "I'm still here" signal. Each driver's position is stored with an expiry time, a of perhaps 30 seconds; a driver whose last ping is older than that simply drops out of the cell's list until the phone checks in again. Nobody has to clean up after them: silence alone takes them out of matching.
CountedLeft outPinged 3 s agoPinged 4 min agoMatching
The best driver is still on another trip
You're outside a hospital. The nearest free driver is 9 minutes away. But another driver is about to drop a passenger just round the corner: one minute to finish that trip, then three minutes to reach you. If the app only looked at drivers who are free right now, you'd wait more than twice as long, and the busy driver would finish their trip and sit idle while you waited.
How it’s handled
Well-built matching asks "when could this car reach the pickup?", not "is it free this second?". For drivers near the end of a trip, it adds the time left on the current ride to the time from the drop point to you, and offers the next ride before the current one ends. The driver finishes, and the next pickup is already lined up. It needs care: if the first trip runs late, the second rider's ETA slips too, so apps only do this when the current trip is nearly over.
Ravi accepted your ride, but two minutes later he cancels: maybe the pickup is on the other side of a jam, or he saw the drop is far from where he wants to end his day. You've already waited two minutes, and if the app now treats you like a brand-new booking, you join the back of the line behind everyone who booked after you.
How it’s handled
The booking keeps its ID and its place: matching runs again straight away for the same booking and gives it priority over newer ones in that area. The app tells you plainly, "Your driver cancelled, finding another". Apps also track cancellations per driver and may limit or penalise repeat cancellers. To cut cancellations in the first place, many show drivers the general direction of the drop before they accept, so they turn down rides they don't want instead of accepting and dropping them.
Cancels at 2 minRider goes firstDriver RaviMatchingNext best driver
How it’s builtAdvancedThe building blocks
BookGPS pingWho is near?Real ETAsDriver foundSave the tripRider appDriver appMatchingLocation serviceRouting engineLive updatesTrip records
Rider app
Sends where you are and where you want to go, shows the fare, and keeps a live connection open so it can show the car coming.
Driver app
Pings its location every few seconds, says whether the driver is free, and shows ride offers with a countdown.
Location service
Every online driver's latest position and status, filed by map cell and kept in fast memory, with old positions expiring by themselves.
Routing engine
Works out real road routes and driving times for the shortlisted drivers, using live traffic.
Matching
Filters and ranks nearby drivers, offers rides one at a time with a timeout, and makes sure each driver is held by only one booking.
Live updates
Passes the driver's pings to the rider's screen, and sends alerts like "Your driver has arrived".
Trip records
The permanent record of every booking and trip: who, where, when, the fare and what happened, saved to disk for receipts, support and payouts.
Notice the split between memory and disk. Driver positions are huge in number, change every few seconds and are useless a minute later, so they live in memory and are allowed to expire. Bookings and trips are fewer, must never be lost and are needed for months, so they go to a database. Using the right store for each kind of data is most of what makes the system fast.
Notice too that the system is built around a booking that changes state: searching, driver offered, driver on the way, on trip, completed or cancelled. Each step has rules about what can come next, so that a cancelled booking can't suddenly start a trip, and a driver can't be on two bookings at once.
The big idea: positions change every few seconds and only the latest one matters, so they live in fast memory, filed by map cell, and the app searches only the few cells around you before ranking drivers by real driving time.
For experienced engineers
The location store is typically an in-memory key-value system sharded by geography (city or region, then cell), since nearly all queries are local; hot cells such as airports and stations may need finer cells or extra replicas. Hexagonal grids are popular because each hexagon's six neighbours sit at the same distance from its centre, so k-ring searches are roughly circular; Uber open-sourced its system, H3, which supports hierarchical resolutions so a sparse suburb can be searched at a coarser level. Candidate generation by cell is cheap; ETA is the costly step, so systems prune to a small shortlist before calling routing, often using precomputed or cached ETAs for nearby pairs. Driver claims use an atomic compare-and-set (or a conditional write with a TTL) on driver status, so a crashed matcher can't leave a driver locked forever. Rather than greedily assigning each request as it arrives, busy markets often batch requests for a second or two and solve an assignment problem across all riders and drivers in the batch, minimising total pickup time; this also lets the system chain trips by including drivers about to drop off. Offer dispatch is a per-booking state machine with idempotent transitions, because driver apps on flaky networks retry their accept messages.
By the numbersAdvancedHow big it gets
Every 4 sroughly how often a driver's phone reports its location
1 lakh+location updates a second, if 4 lakh drivers ping every 4 seconds
7 cellsyour map cell plus the ring of six around it, searched first
Under 1 sto find, filter and rank nearby drivers; the rest of the wait is people
~15 sthe time a driver might get to accept before the offer moves on
2 kma typical first search radius around your pickup, widened if nobody is free
Watch outCommon mistakes
Checking every driver in the city for every booking
A small cab start-up begins with 300 drivers, and its matching code simply loops over all of them for each booking, measuring the distance to each. It's fast enough on launch day. A year later there are 30,000 drivers and 2,000 bookings a minute at peak: that's 6 crore distance checks a minute, and bookings start timing out on Friday evenings, exactly when demand is highest.
Better
File drivers by map cell from the start, so each search looks at a few cells and a few dozen drivers, however big the city gets. The work per booking stays about the same as the business grows a hundred times.
Saving every GPS ping to the main database
A team writes each driver's ping straight into the same database that holds bookings and payments, so they have "everything in one place". At 1 lakh pings a second, the database spends most of its effort saving positions nobody will read again, and booking and payment requests slow down behind them.
Better
Keep each driver's latest position in fast memory, overwriting the old one. If trip routes are needed later (for fares, receipts or disputes), collect the pings for each trip and save them in batches to cheaper storage, separate from the booking database.
Sending one ride to many drivers at once
To find a driver faster, an app sends each new ride to the ten nearest drivers and gives it to whoever taps first. Drivers start racing each other, tapping before they've read the pickup, then cancelling. Nine of them lose every race and feel cheated, and two taps arriving together can assign the ride twice if the code isn't careful.
Better
Offer each ride to one driver at a time with a short timeout, holding that driver for that booking. If speed matters more in some area, offer to a small group only with a strict single-winner rule, and measure whether cancellations rise.
Matching each rider the instant they book, in a busy area
At a station at 9 pm, riders book every second. Matching each one immediately gives each the best driver for them, but not the best overall. Say rider A books first and grabs driver X, 2 minutes away; rider B then gets driver Y, 12 minutes away. Total waiting: 14 minutes. If A had got Y (4 minutes) and B had got X (3 minutes), the total would be 7.
Better
In busy places, collect bookings for a second or two and match the whole group together, a form of , choosing pairings that lower the total wait. Riders don't notice a two-second delay, and on average everyone waits less.
Interview angleIn an interview
"Design Uber" or "design a ride-hailing app" is one of the most common system design questions. It's popular because it mixes a huge stream of small, fast-changing data (driver positions) with careful, must-not-fail data (bookings and payments), and the interviewer wants to see whether you treat them differently.
A strong answer covers:
a quick load: 4 lakh online drivers pinging every 4 seconds is about 1 lakh writes a second, each replacing the last;
driver positions in an in-memory store, filed by map cell, with old entries expiring;
searching the rider's cell and its neighbours, widening if nobody is free;
ranking a short list by real ETA from a routing engine, not straight-line distance;
one offer at a time, with a timeout and a hold that only one booking can win;
the booking as a , stored in a durable database;
live updates to the rider over an open connection, plus push notifications.
Follow-up: "How would you split the location store across many machines?" By geography, since almost every search is local: each city or region, and within it groups of cells, lives on its own machines, with extra capacity for busy cells like airports.
Follow-up: "What if the matching server crashes while a driver is held?" The hold has an expiry, so it releases itself after a few seconds; the booking's state is saved, so another server picks it up and carries on matching.
Follow-up: "How do you stop one driver being assigned to two riders?" Claim the driver in a single step that only succeeds if their status is still "free"; the second claim fails and that booking moves to its next candidate.
Quick checkCheck your understanding
Words in this lessonThe jargon, in plain English
Every technical word used above. In the lesson, tap any word with an ⓘ to see its meaning right there.
Back-of-the-envelope estimate
A quick, rounded calculation, like 1 crore requests a day ≈ 100 a second, used to decide which parts of a design matter. Close enough beats exact.
Batching
Collecting many small things and handling them together, like adding up 1,000 likes in one go instead of one by one.
Database
A program that stores data safely and lets you query it, even after restarts and crashes.
ETA
Estimated time of arrival: how long until the driver, the food or the train reaches you.
Geospatial index
A way of organising locations on a map so the system can instantly answer "what is near this point?" without checking every driver in the city.
GPS ping
A phone telling the server where it is right now, sent every few seconds by a driver's or delivery partner's app.
Heartbeat
A small "I'm alive" message a machine sends every second or so. When heartbeats stop, others assume it has failed.
Lock
A temporary "reserved" tag on something, like a seat, so only one person can change it at a time. Everyone else waits or is told it's taken.
Map cell
The map split into small tiles (often hexagons) so things that are close together share a tile. Searching nearby means checking your tile and its neighbours.
Matching
Pairing two sides, like each rider with the best free driver nearby.
Memory (RAM)
A computer's short-term working space. Reading from it takes about a ten-millionth of a second, far faster than any disk, but it is wiped when the power goes off.
OTP
One-time password: a short code, usually 6 digits, sent to your phone. It works once, and only for a few minutes.
Persistent connection
A line between your phone and the server that stays open, so either side can send something the moment it happens instead of asking again and again.
Push notification
A message the app's server sends to your phone even when the app is closed, like "Your order is on the way".
Race condition
A bug where the result depends on who gets there first. Example: two people both "win" the last seat because the system checked for both before it saved either.
Routing engine
Software that works out the real road path and travel time between two points, including one-way streets, dividers and U-turns.
State machine
A fixed list of stages something moves through, in order. An order goes placed → accepted → cooking → picked up → delivered, never backwards.
Timeout
A limit on how long to wait for something before giving up and reporting an error.
TTL
Time to live: how long a cached copy is trusted before it expires and is fetched again.
Simplified: this explains how systems like this are commonly built, from public talks and standard patterns. Real systems differ in the details.
Enjoyed this? Keep going for free
This lesson is a free preview. Sign up free to save your progress and earn XP, and to unlock all 232 lessons, the simulator challenges and mock interviews.