← all topics Uber board · say it in this order 1 Problem2 Entities + API 3 High-level design4 Deep dives 5 Final + levelsreset

Design Uber: fare, request, match, accept

10M drivers · 2M location writes a second (a ceiling) · 10 s offer countdown, 12 s server window · match in under 1 minute · board rules, one idea per line
SAY THIS SENTENCE FIRST

"A ride request is a short multi-step process with a human in the loop: price it, persist it, find nearby available drivers from a live location index, offer it to one driver at a time with a timeout, and never let a driver hold two offers. Matching has to stay one offer per driver and one driver per ride under retries, crashes and timeouts."

STEP 1 OF 5

Understanding the problem

5 min

Functional Requirements

  1. A rider enters pickup and destination and gets a fare estimate.
  2. A rider requests a ride against that estimate.
  3. The request is matched to a nearby, available driver.
  4. The driver accepts or declines, then navigates to pickup and drop-off.

Below the line (out of scope):

  • Ratings both ways, scheduled rides, and ride categories (X, XL, Comfort).
  • Privacy and GDPR, general redundancy, monitoring, CI/CD.

Non-Functional Requirements

Do the scale math first, because it shows where the simple design breaks
  • Location writes: 10M drivers / 5 s = 2M writes a second, which is a ceiling because 10M counts registered drivers, not online ones.
    • 10M is closer to all registered drivers than to drivers online at once.
  • At that rate a disk database is the wrong tool, and the bill proves it.
    • DynamoDB on-demand, about 100 B per ping, 1 write unit each: 2M × 86,400 s = 172.8B writes a day.
    • × $0.625 per million = about $108K a day, about $39M a year.
    • That buys durability for a value overwritten 5 s later.
  • Offer window: the driver sees a 10 s countdown and the server waits 12 s, so the minute buys at most 5 offers.
    • 60 s / 12 s = 5 sequential offers, fewer if the request waits before its first offer.
  • The geo index is small but write-bound: one node cannot absorb 2M writes a second.
    • 10M × about 100 B = about 1 GB, so memory is fine.
    • One node takes about 100k to 200k writes/s, so 2M/s needs 10 to 20 nodes.
  1. Match fast: under 1 minute to a match or a clear failure.
  2. Strong consistency in matching: no driver on two rides, one offer per driver at a time.
    • A ride is offered to one driver at a time.
  3. Survive spikes: a burst of about 100k requests from one area (a stadium emptying).
DONE WHEN: the interviewer has heard "one driver per ride, one offer per driver" and "2M location writes a second, a ceiling". The first sets up the locking and exact-assignment dives; the second sets up the location-storage dive.
STEP 2 OF 5

Entities + API

5 min

Defining the Core Entities

  • Rider: identity, contact, payment methods.
  • Driver: identity, vehicle, availability status.
    • The accept flips available → on_trip.
  • Fare: pickup, destination, price, ETA, riderId, expiresAt.
    • Pins the quoted price before the rider commits; expires because surge moves.
  • Ride: rider, driver, fare, status, offered_driver, attempt, route, final fare, pickup and drop-off times.
    • offered_driver and attempt name the current offer.
  • Location: the driver's latest lat/long plus the time of that update. Only the latest matters.

API or System Interface

POST  /fare               // { pickupLocation, destination } -> Fare
POST  /rides              // { fareId } -> Ride { status: "requested" }, starts matching
POST  /drivers/location   // { lat, long }, driver id from the session / JWT
PATCH /rides/:rideId      // { accept | deny } -> Ride, with pickup + destination
  • POST /fare is a POST because it creates a Fare row, and that row pins the quoted price.
  • POST /rides takes only the fareId and dedupes on it.
    • The server checks the Fare's riderId and expiresAt, so a double tap or a retry creates one ride.
    • Price, rider id and timestamps come from the server.
  • The driver id on a location ping comes from the session or JWT, never the body.
  • The accept returns pickup and destination for navigation.
  • Never trust client-sent user ids, timestamps or prices.
DONE WHEN: you have said "the client sends a fareId, the server owns the price" and "driver id from the token, never the body".
STEP 3 OF 5

High-level design

10 min, end to end, no dives yet

1) Fare estimate

Fare estimate: price it once, on the server, and pin it in a Fare row RiderClient sends POST /fare through APIGateway to RideService. RideService asks MappingAPI for distance and drive time, prices the trip and writes one Fare row to PrimaryDB. The Fare goes back to the rider through APIGateway. 1) Fare estimate: price it once, on the server, and pin it in a Fare row POST /fare {pickupLocation, destination}. The client never sends a price, a riderId or a timestamp. RiderClient pickup + destination APIGateway auth, rate limit RideService fare estimate + pricing MappingAPI third partydistance + drive time PrimaryDB Fare row: fareId, riderId,price, eta, expiresAt 1. RiderClient sends POST /fare {pickupLocation, destination} 2. APIGateway checks the token, then forwards 3. RideService asks for distance and drive time 4. MappingAPI returns meters and seconds 5. RideService prices the trip and writes one Fare row the row pins the quoted price 6. RideService returns the Fare {fareId, price, eta} 7. APIGateway relays it to the rider the not-so-happy paths: a price, riderId or timestamp from the client is never trusted: the server fills in all three.surge moves, so a Fare carries riderId and expiresAt, and POST /rides rejects an expired or foreign fareId.
  • Rider client → API gateway → Ride Service. The gateway does auth and rate limiting.
  • The Ride Service asks a third-party mapping API for distance and time, then prices the trip.
  • It stores the Fare because it is the quote the rider requests against: a fixed price that expires.

2) Request a ride

Request a ride: persist the ride before matching starts RiderClient sends POST /rides with a fareId through APIGateway to RideService, which checks the Fare, writes a Ride row to PrimaryDB, returns the Ride and hands the rideId to RideMatchingService. 2) Request a ride: persist the ride, then start matching POST /rides {fareId} returns the Ride with status requested. RiderClient taps Request APIGateway auth, rate limit RideService validates the Fare PrimaryDB Ride row: rideId, riderId,fareId, status = requested RideMatchingService finds and offersa driver 1. RiderClient sends POST /rides {fareId} only 2. APIGateway forwards, riderId taken from the JWT 3. RideService checks the Fare, writes a Ride row one ride per fareId 4. RideService returns the Ride to the rider {rideId, status: requested} 5. RideService hands the rideId to matching the not-so-happy paths: a double tap sends the same fareId twice; the dedupe on fareId creates one ride.the ride row is written before matching starts, so a crash does not lose the ride.
  • POST /rides {fareId} reaches the Ride Service, which writes a Ride row linked to the Fare with status requested.
  • Then it kicks off matching and returns the Ride to the rider.
  • Persist before matching, so a crash does not lose the ride.

3) Match to a nearby driver

Match to a nearby driver: search the latest positions, keep the available drivers, rank them DriverClient sends its position to LocationService, which overwrites the latest one in LocationStore. RideService hands a rideId to RideMatchingService, which asks LocationStore for the nearest drivers, drops the ones that are not available, and ranks the rest. 3) Match to a nearby driver: search the latest positions, rank the available drivers Drivers stream positions the whole time. The ranked list is the offer order. RideService ride persisted RideMatchingService drops busy drivers,ranks the rest LocationStore latest lat/long + timeper driver DriverClient online, GPS on LocationService write-only, no reads 1. RideService hands the rideId to matching 2. RideMatchingService asks for the nearest drivers within a radius 3. LocationStore returns the candidates busy drivers included L1. DriverClient sends lat/long POST /drivers/locationabout every 5 s L2. LocationService overwrites the latest position the not-so-happy paths: a dense block can return a top-N made of busy drivers, so the matcher filters on the driver's status before ranking.the offer to the top-ranked driver is diagram 4).
  • Driver clients stream locations to a Location Service, which keeps the latest position per driver.
  • The Ride Matching Service queries for the closest available drivers and ranks them.
  • A geo search returns every online driver in the radius, busy or not, so the matcher drops drivers whose status is not available before ranking.
  • The ranked list is the offer order. With at most 5 offers in the minute, the top of it has to be good.
  • The location store takes up to 2M writes a second and must answer "nearest" fast, so it is a store with a spatial index, not the main database; the location-storage dive picks the store.

4) Offer, accept or decline

Offer, accept or decline: one driver at a time, and the accept is one transaction RideMatchingService records the offer on the Ride and pushes it through NotificationService. The driver's PATCH reaches RideService through APIGateway. On accept RideService commits one transaction on PrimaryDB; on deny it tells matching to offer the next driver. 4) Offer, accept or decline: one driver at a time, and the accept is one transaction PATCH /rides/:rideId {accept | deny}. Decline or silence moves the offer down the ranked list. RideMatchingService ranked candidates,one offer at a time NotificationService APNs / FCM push DriverClient 10 s countdown RideService applies accept or deny APIGateway auth, driverId from JWT PrimaryDB Ride and Driver rows 9. RideMatchingService offers the next driver record, push again,12 s window again 1. RideMatchingService records the offer on the Ride offered_driver = d,attempt + 1 2. RideMatchingService offers the ride to the top driver rideId, attempt n 3. NotificationService pushes the offer to that driver 4. DriverClient sends PATCH /rides/:rideId {accept | deny} 5. APIGateway forwards it to RideService 6. On accept, RideService commits one transaction Ride: requested -> acceptedDriver: available -> on_trip 7. RideService returns the accepted Ride pickup and destination,for navigation 8. On deny, RideService tells matching to move on the not-so-happy paths: no answer in the 12 s server window (driver sees 10 s) counts as a deny: matching offers the next driver in the ranked list.two matchers can pick the same driver, and a late accept can race the move to the next driver; the deep dives handle both.
  • Per offer, the Ride Matching Service records the offer on the Ride, then pushes it.
    • Record: offered_driver = the driver, attempt + 1.
    • Push: through a Notification Service (APNs / FCM).
  • The driver's PATCH accept is one transaction in the Ride Service: Ride requested → accepted, Driver available → on_trip.
  • A decline or no answer in 12 s offers the ride to the next driver in the ranked list.
  • When the ranked list runs out, the ride fails "no driver".
  • Two matchers can pick the same driver at once; the dive on one offer per driver handles it.
  • An accept can arrive after the offer moved on, and a crashed matcher loses its 12 s wait; the dive on drivers who never answer handles both.
DONE WHEN: all four requirements have a path, and you have said out loud that a declined or timed-out offer advances the Ride to the next driver in the ranked list.
STEP 4 OF 5

Potential deep dives

~20 min, interviewer steers
TRIGGER: "how do you store driver locations" / "how do you find nearby drivers"

1) 2M location writes a second: where do they go, and how do you search them?

IN MEMORY · GEOADD OVERWRITES · SWEEP THE STALE ONES
Bad Solution: every ping to the main database, query lat/long directly
  • Write each ping as a row and search with a lat/long range.
    • B-tree indexes do not answer 2D "nearest" queries.
    • 2M writes a second sinks the database.
Good Solution: batch pings into a geospatial database
  • Batch pings over a short interval into a geospatial database (a quad-tree style index, or PostGIS).
    • Proximity search works, but the batch delay makes positions stale.
Great Solution: an in-memory geo index with a last-seen sweeper
  • Redis stores each driver in a sorted set with the geohash as a 52-bit score. GEOSEARCH answers "drivers within r of this point".
  • Each GEOADD overwrites the driver's last position. There is no history to store.
  • Stale drivers leave through a last-seen sorted set and a sweeper that removes anyone silent for 30 s.
    • Last-seen is scored by update time, written in the same pipeline as the GEOADD.
    • The sweeper runs every few seconds and ZREMs from both (a geo set is a sorted set; no GEOREM).
    • Not a TTL: Redis TTL works on whole keys, and the geo set is one key.
  • The search reads available drivers only.
    • Keep a separate geo set of available drivers: ZREM on offer or trip, GEOADD when free.
    • Or over-fetch with COUNT and drop drivers who hold a pending offer or are not available.
  • Durability is a small concern: an emptied index refills within one maximum ping interval, 15 s.
    • Persistence (RDB/AOF) or Sentinel failover covers the common case.
Location at scale: an in-memory geo index, and stale drivers swept out DriverClient sends its position to LocationService, which GEOADDs it to DriverGeo and ZADDs the ping time to LastSeen in one pipeline on a Redis shard. StaleSweeper finds drivers silent for 30 s in LastSeen and removes them from both sets. RideMatchingService runs GEOSEARCH on DriverGeo and gets the nearest driver ids back. Location at scale: an in-memory geo index, and stale drivers swept out 10M drivers / 5 s = 2M writes/s (an upper bound). One Redis primary takes 100k to 200k, so 10 to 20 shards. RedisShardone of 10 to 20, sharded by geo cell LastSeen (sorted set) member = driverIdscore = time of the last ping DriverGeo (geo set) member = driverIdscore = 52-bit geohash DriverClient adaptive interval:parked: less often, at most 15 smoving, turning, near a pickup:more often LocationService driverId from the JWT StaleSweeper runs every few seconds RideMatchingService drops drivers that arelocked or on a trip 1. DriverClient sends lat/long about every 5 sby default, adaptive,at most 15 s 2. LocationService GEOADDs the new position overwrites the last one 3. LocationService ZADDs the ping time same pipeline as the GEOADD 4. StaleSweeper removes members silent for 30 s ZRANGEBYSCORE, then ZREM 5. StaleSweeper ZREMs the same drivers from DriverGeo a geo set is a sorted set 6. RideMatchingService runs GEOSEARCH around the pickup BYRADIUS ASC, COUNT over-fetchesso busy drivers can be dropped 7. DriverGeo returns the nearest ids the not-so-happy paths: Redis TTL expires whole keys and DriverGeo is one key, so a driver cannot expire alone: that is why LastSeen and the sweeper exist.a failover that loses the index refills within one maximum ping interval (15 s): every online driver pings at least that often.the 15 s cap sits under the 30 s sweep, so a parked online driver is never swept.a search near a shard edge queries every shard whose cells meet the radius and merges by distance.busy drivers: drawn here is the over-fetch, filtered on the lock and driver status.the other option is a separate available-drivers geo set: ZREM on offer or trip, GEOADD when free.
TRIGGER: "that is still a lot of writes" / "what about battery"

2) Too many location updates: how do you send fewer?

ADAPTIVE INTERVAL ON THE CLIENT · CAPPED AT 15 S, UNDER THE 30 S SWEEP
Bad Solution: every driver pings on a fixed 5 s interval
  • Every online driver sends a ping every 5 s, moving or parked.
    • That is the full 2M writes a second.
    • A parked driver's pings carry no new position and still drain the battery.
Good Solution: a longer fixed interval for every driver
  • Raise the ping interval for every driver.
    • Writes and battery use drop in proportion.
    • Positions go stale for fast, turning, or near-a-pending-request drivers, the ones a match depends on.
Great Solution: adaptive update intervals on the client, capped at 15 s
  • Stationary or slow drivers report less often than the 5 s default.
  • Fast, turning, or near-a-pending-request drivers report more often, because those are the positions a match depends on.
  • The interval is capped at 15 s for any online driver, so the 30 s sweeper never drops a parked one.
    • The cap also bounds recovery: an emptied index refills within 15 s.
  • Each ping is a GEOADD plus a ZADD on the last-seen set, in one pipeline.
TRIGGER: "two matchers pick the same driver"

3) How do you keep one offer per driver at a time?

LOCK THE DRIVER WITH A TTL · COMPARE-AND-DELETE · THE ACCEPT IS A CONDITIONAL WRITE
  • This is the strong-consistency requirement from step 1.
  • Same shape as Ticketmaster's seat hold: reserve briefly, release on timeout.
Bad Solution: each matcher locks in its own memory with its own timer
  • Each matcher instance keeps a set of "locked" drivers and a timer per offer.
    • No coordination between instances, so two matchers offer the same driver.
    • A crashed instance leaves the lock forever.
Good Solution: a status column in the database, a timer in the service
  • Set outstanding_request on the driver row when offering; clear it on answer or timeout.
    • Every matcher reads the same row, so coordination is solved.
    • The timer dies with the process, so a cron sweep has to clear stuck locks.
Great Solution: a Redis lock on the driver id with a TTL, plus the conditional accept
  • Lock the driver for 12 s: SET lock:driver:{id} {rideId:attempt} NX PX 12000. One matcher wins; the loser moves to its next candidate.
  • The lock expires by itself if the driver never answers, so there is no sweep and no stuck driver.
  • Release with a compare-and-delete (a Lua script) on the value, otherwise a matcher deletes a lock that expired and another matcher re-acquired.
  • 12 s is a grace period over the driver's 10 s countdown, so an accept tapped at 9.9 s lands inside the lock.
  • The lock only stops double offers; an accept commits only if the ride is still offered to this driver and the driver is still available. That conditional write, which also checks attempt n, makes the assignment exact.
    • A Redis failover with async replication can lose a lock: at worst a double offer.
    • The accept is one transaction of two conditional writes in the Ride Service:
      • Ride requested → accepted only if offered_driver = me AND attempt = n: stops a late accept on a ride that moved on.
      • Driver available → on_trip only if still available: stops one driver landing two rides.
  • Cost: the design depends on the lock store's availability. Acceptable, because locks live seconds.
TRIGGER: "a stadium empties" / "what if a matcher crashes"

4) How do you avoid dropping requests at peak?

QUEUE IN FRONT OF MATCHING · PARTITION BY REGION · COMMIT ON DURABLE HANDOFF
Bad Solution: handle requests as they arrive, no buffer
  • The Ride Service calls a matcher directly for every request.
    • Spikes overwhelm the matchers.
    • A crashed matcher loses the requests it held.
Good Solution: a queue in front of matching, offset committed after the match
  • Requests land in a queue, matchers scale on its depth, and a matcher commits the offset once the ride is matched.
    • A crash before the commit leaves the request for another consumer, so nothing is lost.
    • Kafka commits a contiguous prefix per partition and a match takes up to 60 s, so the partition stalls behind its slowest ride.
Great Solution: a regional queue in front of matching, committed on the durable handoff
  • Requests land in a queue, and matchers scale on its depth. A burst becomes a backlog, not an outage.
  • Partition by region, so a stadium in one city does not slow matching in another.
  • Commit the offset once the request is handed to the durable workflow (the dive on drivers who never answer).
    • A crash before the handoff leaves it uncommitted, so another consumer picks it up.
    • Not after the match: Kafka commits a contiguous prefix per partition, and a match takes up to 60 s, so the partition stalls behind its slowest ride.
  • The handoff is idempotent on rideId, so a redelivered ride that is already matching or matched is skipped.
  • Two costs: running the queue (use a managed one), and head-of-line blocking in a FIFO, which a priority queue addresses.
TRIGGER: "the driver never taps anything" / "who owns the timeout"

5) What happens when a driver never answers?

A HUMAN IN THE LOOP IS A WORKFLOW · DURABLE TIMER · ONE WINNER BETWEEN ACCEPT AND TIMEOUT
  • Matching has a human in the loop: offer, wait, then accept, decline or silence.
  • Whatever owns the 12 s wait has to survive a crash, or the ride sits in requested forever.
Bad Solution: the matcher holds the 12 s timer in its own memory
  • The matcher waits 12 s per offer in its own process, then moves to the next driver.
    • A crashed matcher loses the timer, so the ride sits in requested forever.
Good Solution: a delay queue scheduled with each offer
  • With each offer, schedule a 12 s delayed message (for example SQS) carrying the attempt number; when it fires, advance the Ride to the next driver.
    • The timer outlives a crashed matcher.
    • SQS cannot cancel a delayed message, so a stale one updates zero rows and is dropped.
    • Cost: you hand-manage the loop's state across messages and rows.
Great Solution: durable execution (Temporal, AWS Step Functions) with a compare-and-set advance
  • The matching loop is one workflow per ride (MatchingWorkflow) that waits 12 s per offer. Offer, wait, finish on accept, move on on decline or timeout.
  • Each move to the next driver d' is one compare-and-set on the Ride's attempt counter n: set attempt = n+1, offered_driver = d', only if status = requested AND attempt = n.
    • UPDATE ride SET attempt = n+1, offered_driver = d' WHERE id = :ride AND status = 'requested' AND attempt = n
    • The first offer is the same write from attempt = 0.
    • Order per offer: lock d', advance, push. No driver left: offered_driver = NULL, ride fails "no driver".
  • One winner: the accept and the advance both check attempt = n, so whichever commits second updates zero rows. A late accept (second 13) finds attempt = n+1.
  • The workflow's state survives crashes, so the timer and the position in the ranked list resume on another worker.
  • Cost: a workflow engine (Temporal, Step Functions) is a new system to run and learn.
    • Uber built Cadence, its general-purpose workflow engine and Temporal's ancestor.
TRIGGER: "how does this scale further" / "what about another continent"

6) How do you scale further?

SHARD BY GEO CELL · SCATTER-GATHER ONLY AT BOUNDARIES · REPLICAS FOR READS, SHARDS FOR WRITES
Bad Solution: vertical scaling
  • Buy a bigger box.
    • Costly and capped.
    • A single point of failure.
Good Solution: add read replicas
  • Put read replicas behind each primary.
    • Reads spread, and a replica takes over when the primary fails.
    • Every write still lands on one primary, and one node takes about 100k to 200k writes/s against 2M.
Great Solution: shard by geo cell, with read replicas
  • The shard key is a geo cell (a geohash prefix, or an S2/H3 cell), and consistent hashing maps cells to nodes.
  • A search queries only the shards owning cells that meet its radius and merges by distance. Away from a boundary that is one shard.
  • A driver crossing a boundary is removed from the old shard, or the merge dedupes by driver id.
  • Sharding spreads the 2M writes a second; read replicas spread reads and handle failover.
  • Services, queues and data split geographically, which cuts latency.
    • The Driver row is homed in the driver's current region, so it normally shares a shard with the Ride.
DONE WHEN: you have opened two or three dives properly, and said "efficiency lock, conditional write" before the interviewer asks what happens on a Redis failover.
FLASHCARDS · THE FIVE HARDEST PROBESshow all (interview mode)
2M location writes a second: where do they go, and why not the main database?
  • Into an in-memory Redis geo set, sharded by geo cell. GEOADD overwrites the last position.
  • Only the latest position matters; an emptied index refills within 15 s.
  • A disk database pays for durability nobody needs: B-trees do not answer 2D nearest, and DynamoDB at 2M/s costs about $108K a day.
  • Stale drivers leave through a last-seen sorted set and a sweeper (ZREM from both), because Redis TTL works on whole keys.
Two matchers pick the same driver at the same moment. What stops a double offer?
  • A Redis lock per driver: SET lock:driver:{id} {rideId:attempt} NX PX 12000. One SET wins; the loser moves to its next candidate.
  • The TTL frees the driver if the offer is never answered, with no sweeper.
  • 12 s on the server against a 10 s countdown, so a tap at 9.9 s lands inside the lock.
  • Release is a compare-and-delete on the value, so a matcher never deletes a lock another matcher has since acquired.
  • A lock lost on failover means at worst a double offer; the Driver-row write stops a double assignment.
The driver accepts at second 13, after the 12 s server window moved the offer on. What happens?
  • The accept is a conditional write: Ride requested → accepted only if offered_driver = me AND attempt = n.
  • At 12 s the workflow advanced the Ride and set attempt to n+1, so the accept updates zero rows and the driver sees "offer expired".
  • Both writes check attempt = n while the ride is requested, so whichever commits first wins.
  • Driver side: available → on_trip in the same transaction, so one driver never holds two rides.
A matcher crashes holding a request mid-offer. How is the request not lost?
  • The request sits in a queue partitioned by region.
  • Its offset commits only once the request is handed to the durable workflow, so another consumer picks it up after a crash.
  • The workflow (Temporal) keeps its state and 12 s timer through the crash and resumes on another worker.
  • The handoff is idempotent on rideId, so a redelivered ride that is already matching or matched is skipped.
  • Committing after the match instead would stall the partition behind its slowest ride, up to 60 s.
GEOSEARCH in a dense block returns 20 drivers, all busy. What now?
  • GEOSEARCH returns every online driver in the radius, busy or not, so "available" needs its own mechanism.
  • Keep a separate available-drivers geo set: ZREM on offer or trip, GEOADD when free.
  • Or over-fetch with COUNT and filter by lock and status.
  • Widen the radius if still empty.
STEP 5 OF 5

Final design + what is expected at each level

wrap

Final Design

Uber: final design. One driver per ride, one offer per driver, no request lost RiderClient reaches RideService through APIGateway; RideService prices with MappingAPI, writes Fare and Ride rows to PrimaryDB and enqueues the rideId on RideRequestQueue. MatchingWorkflow, a durable workflow, searches RedisGeoIndex, locks a driver in DriverLocks, advances the Ride in PrimaryDB and sends the offer through NotificationService. The driver's PATCH returns through APIGateway; on accept RideService commits one transaction and signals the workflow. Drivers ping LocationService, which writes RedisGeoIndex. Uber: final design. One driver per ride, one offer per driver, no request lost a lock keeps offers single, conditional writes make the assignment exact, a durable workflow owns every timeout. L = the location path, always running. RiderClient fare, request APIGateway auth, rate limit,ids from the JWT RideService fares, rides,accept or deny MappingAPI distance + drive time NotificationService APNs / FCM RideRequestQueue partitioned by region ride ride ride MatchingWorkflow durable execution(Temporal)offer, wait 12 s(driver sees 10 s),next driver PrimaryDB Rider, Driver, Fare, Ridesharded by region+ read replicas RedisGeoIndex DriverGeo + LastSeensharded by geo cellStaleSweeper ZREMs driverssilent for 30 s DriverLocks (Redis) lock:driver:{id} =rideId:attemptTTL 12 s = 10 s countdown+ 2 s grace DriverClient adaptive pings LocationService write-only 1. RiderClient POST /fare, then POST /rides 2. APIGateway forwards 3. RideService asks for distance and drive time 13. On accept, RideService commits one transaction Ride: requested -> accepted if offered_driver = me AND attempt = nDriver: available -> on_trip, if still available 4. RideService writes Fare and Ride rows 5. RideService enqueues rideId 6. RideRequestQueue hands the rideId to a worker start is idempotenton rideId, then theoffset commits 14. RideService signals theworkflow: accepted or denied 9. MatchingWorkflow advances the Ride attempt + 1, offered_driver = d,if status = requestedAND attempt = the value read 7. MatchingWorkflow GEOSEARCHes available drivers near the pickup 8. MatchingWorkflow locks the top free driver SET lock:driver:{id}{rideId:attempt} NX PX 12000 10. MatchingWorkflowsends the offer 11. NotificationService pushes the offer to the DriverClient 12. DriverClient sends PATCH /rides/:rideId {accept | deny} L1. DriverClient pings lat/long L2. LocationService GEOADDs and ZADDs, one pipeline the not-so-happy paths: a worker dies mid-offer: the workflow's state and 12 s timer resume on another worker; a redelivered rideId that is already matching or matched is skipped.Redis fails over and loses a lock: at worst a double offer. the conditional accept still lands one driver per ride and one ride per driver.an accept after the offer moved on finds attempt = n+1 and updates zero rows. a search near a shard edge queries each shard it touches and merges by distance.
  • Path: gateway → Ride Service → queue by region → MatchingWorkflow; drivers ping the Location Service into Redis.
    • The Ride Service prices with the mapping API and writes Fare and Ride rows.
    • The queue's offset commits once the workflow starts; the start is idempotent on rideId.
    • MatchingWorkflow is the Ride Matching Service, built as a durable workflow.
    • Pings, at an interval capped at 15 s, write the geo index plus a last-seen set; a sweeper removes drivers silent for 30 s.
  • Per offer: lock the next driver d' (SET NX PX 12000), advance the Ride from attempt n to n+1 with offered_driver = d', only if it is still requested at attempt n, then push.
    • The Ride Service signals the workflow on an accept or a decline.
    • A 12 s timeout or a decline runs the same advance for the next driver.
  • Accept is one transaction: Ride requested → accepted if offered_driver = me AND attempt = n; Driver available → on_trip only if still available.
  • The primary DB is sharded by region with read replicas; the Redis geo index is sharded by geo cell. Ride and Driver normally share a shard, because the Driver row moves with the driver's region.
  • The invariant: every ride ends with at most one driver and every driver with at most one trip. The lock keeps offers single in the normal case, one transaction of conditional writes on Ride and Driver keeps assignment exact in every case, and a durable workflow owns every timeout so no request is lost.
    • A lost lock means at worst a double offer.
    • A crashed matcher's workflow resumes on another worker.
    • An emptied index refills within 15 s.

What is Expected at Each Level

  • Mid (E4):
    • Clear API and data model.
    • A working high-level design that meets the requirements.
    • Knows a spatial index is needed, even without naming one.
    • At least the Good answer to driver locking.
  • Senior (E5):
    • Gets through the high-level design fast.
    • Goes deep on at least 2 of the deep dives, most often location search, driver locking and request queueing.
      • Location writes: batches pings into a geospatial database (a quad-tree style index, or PostGIS), and says the batch delay leaves positions stale.
      • Fewer location updates: raises the ping interval for every driver, and says positions then go stale exactly where a match depends on them.
      • One offer per driver: locks the driver with a TTL in a distributed cache (Redis SET NX PX), and says a failover can lose the lock.
      • Peak load: puts a queue in front of matching that matchers scale on, and says committing after the match stalls the partition behind its slowest ride.
      • Drivers who never answer: schedules a 12 s delayed message with each offer, and says a stale one must update zero rows because SQS cannot cancel it.
      • Scaling further: adds read replicas for reads and failover, and says every write still lands on one primary.
    • Weighs the trade-offs of each choice.
    • Knows sharding and replication for scale.
  • Staff+:
    • Deep on 3 or more areas.
    • Proactive: the interviewer only focuses, never steers.
    • Practical judgment about technologies.
    • Insight the interviewer did not already have.
DONE WHEN: you can point at the final diagram and say, in one breath, in-memory geo index with a sweeper, lock the driver with a TTL, conditional write on accept, queue by region, durable workflow owns the timeout.