Skip to the page

India-scale design · senior

Live order tracking and ride hailing

Location data is high-rate, low-value writes. Keep it in memory in a spatial index, stream it, and send only what each screen needs. Matching must claim a driver atomically.

The notes

What you must know

  • Order tracking: status changes are events (placed, accepted, picked up, delivered) on Kafka. A tracking service keeps the current state; the app gets push updates and fetches the state on open.
  • Location: the partner app sends every few seconds while on an order (batched, adaptive to speed and battery) to a light ingest gateway, then a stream. The latest point per partner is in Redis with a TTL; history goes to cheap storage for analytics.
  • Numbers: 3 lakh active partners sending every 5 seconds is 60,000 writes a second. Fine for a sharded in-memory store, far too much for row updates in the orders database.
  • To customers: WebSocket or SSE only for people watching that order (publish by order id); polling every 10 to 15 seconds as a fallback; throttle updates. Show last known position with updated 2 min ago, smooth movement on the phone, and keep the ETA stable.
  • Ride hailing location service: the latest location per driver in memory (Redis GEO or an in-memory grid) indexed by geohash or H3 cell, each cell holding its set of free drivers. 5 lakh online drivers every 4 seconds is about 1.25 lakh writes a second: shard by city or cell.
  • Matching: search the rider cell and rings around it, filter by vehicle type and status, rank by real ETA (not straight-line distance), and offer to one driver at a time with a short lease (status = offered, TTL) so no double assignment. If the offer expires, go to the next driver.
  • Trip state machine (requested, accepted, arrived, started, ended, paid) in a durable store, with events on Kafka for billing, notifications and analytics. Surge: supply and demand per cell per minute from the stream, cached as a multiplier and shown as a quote valid for a few minutes. Fare comes from the recorded trip, not the phone.
  • Never write every ping to the main orders database, ORDER BY distance over every driver in SQL, or send all partner locations to every client.

The red pen

Common traps: mistake → fix

  • Mistake: Every customer polls every second

    Fix: use push for watched orders only.

  • Mistake: Write pings to the orders database

    Fix: it overloads; use memory and a stream.

  • Mistake: Order by distance in SQL for each request

    Fix: use a spatial index.

  • Mistake: Compute the fare on the phone

    Fix: use recorded trip data on the server.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design live order tracking for food delivery.
  2. How much write load do 3 lakh partners create?
  3. Design a ride-hailing backend. How do you find nearby drivers?
  4. How do you avoid giving one driver to two riders?
  5. How do you handle gaps in location updates?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview