Explained step by step
Customer functional requirements: see nearby cabs with estimated time of arrival (ETA) and price, book a ride to a destination, and see where the driver is. Driver: accept or deny the ride, see where to pick up the customer, and mark the trip complete. Non-functional: high reliability, high availability with minimal latency, and it must scale. Extended: rate the trip, process payments and metrics. It's like a phone taxi service, but with a map and in real time.
With 100 million daily active users, 1 million drivers and 10 million rides per day. If each user performs 10 actions, like checking fares or booking a ride, that's 1 billion requests per day: about 12,000 per second. At 400 bytes per message, that's 400 GB per day; over 10 years, about 1.4 PB, with about 5 MB per second of bandwidth. It's like counting how many calls a nationwide taxi dispatch gets.
Here's how a ride works: the customer requests a ride with source, destination, cab type and payment method; the ride service registers it, finds nearby drivers and calculates the ETA; it broadcasts the request to nearby drivers; if one accepts, the customer sees their live location and ETA; the driver picks them up and starts; on arrival, they mark the ride complete and payment is collected; and the customer can rate. That's 7 steps. It's like ordering a pizza with tracking: you order, it's accepted, you see the scooter on the map and finally you rate.
To send live locations there are 2 models, like in a chat. Pull: the client sends its location every so often over HTTP; it doesn't scale, because it generates a huge number of requests and most responses bring nothing new. Push: a long-lived connection, with WebSockets, where the server sends data as soon as it changes. Push fits best. Also, the app must keep sending GPS in the background. It's like a delivery truck's GPS: dispatch sees it move without calling the driver.
To find nearby drivers there are 3 options. SQL: search latitude and longitude within a radius; it works, but it's slow with lots of data. Geohashing: compare the customer's geohash with the drivers', stored in memory with an index. Quadtrees: a tree that splits the map into 4 quadrants and only divides a node after a threshold; it's updated with each new location, and to relieve its servers an in-memory cache like Redis is used. The quadtree looks ideal. It's like looking for a pharmacy: you don't check the whole country, only your neighborhood.
With huge numbers of customers requesting rides at once, race conditions can happen: 2 customers assigned to the same driver. To avoid it, the matching logic is wrapped in a mutex, a lock that lets just 1 through at a time, and every action runs in a transaction. Then, among nearby drivers, they're ranked by average rating, relevance and feedback, and the best ones are notified first. It's like the last seat on a bus: if 2 people rush at once, someone has to decide who sits.
With high demand, surge pricing is used: the price goes up for a while when there are more requests than drivers, and that extra is added to the base price. For payments, instead of building everything, a third-party processor like Stripe or PayPal is used, which notifies the app with a webhook when done. Notifications go through Kafka to FCM or APNS, and the cache stores recent locations. It's like airfares in high season: more people want to travel and the price goes up.