Design a Ride-Hailing App (like Uber)
Design a ride app that tracks drivers as they move, finds the drivers near a rider, and sends one of them to the rider.
Think of a ride-sharing service like air traffic control for taxi drivers. Your phone shares your GPS pin, and a radar map pairs you with the closest idle cab within a 2-mile radius.
- Clients
- Rider app
- Driver app
- Entry
- Gateway
- Services
- Ride matching service
- Location workers
- Queues, caches
- Location stream
- Geo index
- Driver lock
- Data, outside
- Trips database
- Push service
1. Requirements and scope
- Drivers broadcast GPS location every 4 seconds.
- Riders can request nearby available drivers within a 5km radius.
- Match rider with best available driver and track trip progress in real time.
- Sub-second driver discovery latency.
- High availability for matching and trip lifecycle.
- Accurate geospatial proximity filtering.
2. Back-of-the-envelope numbers
- Writes: 1,250,000 location updates a second (93%)
- Reads: 100,000 driver searches a second (7%)
Write-heavy: about 13 writes for each read. A queue and a store that is fast at writes help most here.
3. API
4. Data model and storage
REDIS GEO index key="drivers:active", member="{driverId}", longitude, latitude5. The design, in three versions
Version 1: Relational PostGIS Queries
Each driver location is written straight into PostgreSQL, with PostGIS for map searches.
Ride-Hailing App (like Uber): Version 1: Relational PostGIS Queries Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Data, outside
The steps in words0 of 3 steps shown
Rider app to Ride matching service
A rider asks for a ride near a point on the map.
Ride matching service to Trips database
It asks PostgreSQL for the drivers within 2 km.
Ride matching service to Rider app
The nearest driver goes back to the rider.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathA driver reports a location
- Driver app
- Location service
- Geo index
- Trip database
Driver app to Location service
Every 4 seconds the driver's app sends its position.
Location service to Geo index
The service turns the position into a cell id, a small hexagon on the map. It updates that driver's entry in memory.
Location service to Trip database
For a driver on a trip, positions are also saved in batches for the trip history.
Read pathA rider requests a ride
- Rider app
- Ride matching engine
- Geo index
- Driver lock
- Driver app
Rider app to Ride matching engine
A rider asks for a ride from a pickup point.
Ride matching engine to Geo index
The engine finds the rider's cell and its neighbours, and lists the free drivers inside them.
Ride matching engine to Driver lock
It picks the best driver and tries to reserve them. The reserve step changes the driver from available to reserved, only if still available.
Ride matching engine to Driver app
It sends the offer to the driver, who has about 15 seconds to accept.
Ride matching engine to Rider app
On accept, the trip is saved and both apps start to show each other's position.
What breaks, and what happens then
Two riders are matched to the same driver at once
- What users see
- Both would be told the driver is coming.
- What the design does
- The reserve step succeeds for one request only. The other request moves to the next nearest driver.
A location server restarts
- What users see
- Its positions in memory are gone.
- What the design does
- Drivers report every 4 seconds, so the index refills within seconds. No backup of positions is needed.
The driver does not answer the offer
- What users see
- The rider waits.
- What the design does
- The reservation expires after about 15 seconds, and the engine offers the trip to the next driver.
One city has a sudden rush
- What users see
- The servers for those cells get far more load than the others.
- What the design does
- Cells are spread over servers with a hash ring, and busy cells can be split across more servers.
6. Deep dives
7. Follow-up questions
- How do you prevent two nearby riders from booking the same driver? (Answer: Change the driver from AVAILABLE to RESERVED in one atomic step, a compare-and-set, with a 30-second expiry. Only one request can win.)
What it costs
Location updates are the load: 1.25 million a second. Almost all of them are overwritten within seconds, so keep them in memory and save only a sample to disk. Sending updates less often while a driver waits also cuts the bill.
Another way to design it
Geohash cells in Redis or a PostGIS query can replace the H3 ring. Both are simpler and work well for one city. The custom ring pays off when many cities share one fleet of servers.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 1.25 million location updates a second and 100,000 search queries a second. It explains a geospatial index such as geohash and goes deep on one part, such as matching.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Riders request nearby drivers within 5km, and drivers ping GPS every 4 seconds. Does 'best driver' mean nearest, or does it also weigh rating and estimated arrival? I will assume nearest-available matching, sub-second search, and that trip history can be eventually consistent.
Riders request a nearby driver, and I match them to whichever available driver is geographically closest, full stop. Let me start building the location index and the matching API.
Shows: Unclear questionsThe difference: The weak answer assumes 'best driver' means only nearest, without asking whether rating or estimated arrival time should factor in too.
Estimates
5 million drivers pinging every 4 seconds is 1.25 million location updates a second, kept only in memory, not written per ping. Nearby-driver searches run about 100,000 a second. Trip history in PostGIS adds roughly 25 TB a year, far less than logging every ping would.
Each of the 1.25 million location pings a second needs its own row. So I would size Cassandra for 1.25 million durable writes a second, replicated three times.
Shows: DepthThe difference: Writing every ping to a durable database wastes capacity. The strong answer keeps live location in memory; only the index must sustain that rate.
Core design
Drivers' pings write into a Redis GEO index sharded by region. That spreads citywide load across many nodes, though one dense cell can still land on a single node. A rider's search queries neighbouring cells for available drivers, and reserving one is an atomic compare-and-set from AVAILABLE to RESERVED with a short TTL.
Every driver location update writes to one Redis instance holding a single GEO index for the whole world. A rider's search runs one GEORADIUS query against that same index.
Shows: DepthThe difference: One Redis instance cannot take 1.25 million writes a second alone. Sharding the index by region spreads that load across many nodes.
Deep dive
The hard part is uneven density, not raw volume. A fixed-size cell downtown can hold thousands of drivers while a nearby rural cell sits empty, so its one node overloads. I would use finer cells where density is high, split a hot cell further, and add read replicas for that node.
I would pick one cell size everywhere, say a 1km geohash, and give each cell to a single shard, however many drivers it holds.
Shows: DepthThe difference: Assuming even density means a busy downtown cell overloads its one shard, while a rural cell's shard sits idle. Finer cells and replicas even out a hot cell's load instead.
Failures and trade-offs
If a node holding part of the in-memory index crashes, its drivers vanish from search until their next ping, at most 4 seconds later. We never treated that memory as durable. A short heartbeat also marks a driver who goes offline mid-trip unavailable within seconds.
If a node holding driver locations crashes, I would replicate every update to another node synchronously first, so no location update is ever lost.
Shows: Trade-offsThe difference: Synchronous replication of 1.25 million updates a second adds cost the design does not need, since a stale driver re-pings within 4 seconds anyway.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Ride-Hailing App (like Uber) Design a ride app that tracks drivers as they move, finds the drivers near a rider, and sends one of them to the rider. What users must be able to do: - Drivers broadcast GPS location every 4 seconds. - Riders can request nearby available drivers within a 5km radius. - Match rider with best available driver and track trip progress in real time. How well it must work: - Sub-second driver discovery latency. - High availability for matching and trip lifecycle. - Accurate geospatial proximity filtering. Numbers to assume: - 5 million active drivers each send their location every 4 seconds: 5,000,000 ÷ 4 = 1.25 million updates a second. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 1.25 million location updates a second and 100,000 search queries a second. It explains a geospatial index such as geohash and goes deep on one part, such as matching. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]