Hello! Welcome to the first lesson in our module on "Designing Product & Platform Systems."
In our last lesson, we took a deep dive into designing a navigation and ETA system. We established how to model the world as a graph, use hierarchical partitioning for scalable routing, and incorporate real-time traffic data through a streaming pipeline. We also explored how a hybrid ML model can enhance accuracy, a key detail for a Staff-level design.
Today, we're zooming out to design the complete ride-sharing system with a focus on Uber. We'll integrate the ETA service we designed previously and build the other critical components around it. Specifically, we'll focus on the three pillars of a ride-sharing service:
- Driver-Rider Matching: How do you find the best driver for a ride request efficiently and consistently?
- ETA: How is our previously designed ETA system integrated?
- Surge Pricing: How does the system dynamically adjust pricing based on real-time supply and demand?
This is a canonical system design question, and for a Staff+ role at a company like Uber, demonstrating mastery of the trade-offs in this domain is crucial.
1. Scoping the System: Functional and Non-Functional Requirements
Before drawing any boxes and arrows, we must understand what we're building and what qualities it must possess. A ride-sharing app has numerous features, but in an interview, you must prioritize the core functionality.
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
To begin, let's watch a segment from a mock interview with an ex-Meta Staff Engineer. He does an excellent job of defining the functional and non-functional requirements for an Uber-like system. Pay close attention to how he scopes the problem and quantifies the system's desired qualities.
Please watch from 03:04 to 10:11. This section covers: Functional Requirements (03:04 - 06:12): Defining the core user actions like getting a fare estimate, requesting a ride, and drivers accepting requests. Notice the deliberate exclusion of features like multiple car types or ratings to maintain focus. Non-Functional Requirements (06:12 - 10:11): Discussing critical system properties like low-latency matching, consistency (a ride is matched to only one driver), availability, and handling high-throughput surges. This is where the Staff-level thinking begins.
Based on the video and our learning goals, let's crystallize the requirements:
Functional Requirements:
- A rider can input a pickup and destination to get a fare and ETA estimate.
- A rider can confirm the request to be matched with a nearby, available driver.
- A driver can receive and accept or decline a ride offer.
- Both rider and driver can see each other's location in real-time during pickup and the trip itself.
Non-Functional Requirements:
- Low Latency Matching: A rider should be matched with a driver in under a minute.
- High Availability: The system must be available 24/7. Downtime directly translates to lost revenue and user trust.
- Consistency: A ride must be assigned to exactly one driver. A driver must not be juggling multiple simultaneous ride offers. This is a critical correctness constraint.
- Scalability & High Throughput: The system must handle millions of concurrent users and location updates, especially during peak hours or large events (e.g., a concert ending).
2. High-Level Architecture and API Design
With the requirements set, we can define the API endpoints that will drive our system and sketch out the main service components.
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
Continuing with the same mock interview, the presenter now outlines the core data entities and the API contract. This step translates our abstract requirements into concrete technical specifications.
Watch from 12:03 to 20:42. Focus on: Core Entities: Identifying the main nouns of the system (Ride, Driver, Rider, Location). API Design: How each functional requirement is mapped to a RESTful endpoint (e.g., POST /ride/fair_estimate, PATCH /ride/request). Security Note: The important point about not passing user_id in the request body and instead relying on session tokens (JWT) from the header.
This structured approach gives us a solid foundation. Now, let's build the architecture that serves these APIs. The diagram below shows a comprehensive architecture for a taxi aggregator. While it includes many components, we'll focus on the core flow for matching, ETA, and pricing.

The end-to-end flow for a ride request involves three key stages, which we will now explore as deep dives.
3. Deep Dive 1: Fare Estimation and Surge Pricing
When a rider requests a fare estimate, the system needs to calculate a price. As we saw in the systemdesignschool.io article LINK, this is typically a function of a base fare, distance, and time.
fare = base_fare + (distance_km × per_km_rate) + (duration_min × per_min_rate)
The distance and duration come directly from the Navigation and ETA service we designed in the last lesson. The Ride Service calls this service to get the optimal route and predicted travel time.
However, a static formula isn't enough. To balance the marketplace, we need surge pricing.
The Problem: At 5 PM on a Friday, rider demand skyrockets. At 2 AM on a Tuesday, driver supply is low. How do we incentivize more drivers to come online during high demand and ensure riders can still get a ride?
The Solution: Real-Time Supply & Demand Calculation
Surge pricing is a direct function of the supply-to-demand ratio in a specific geographic area at a specific time. Calculating this requires the same real-time streaming infrastructure we used for traffic data.
Deep Dive E: Streaming features for ETA & pricing (Flink + smoothing)
The article 'Architecting an Uber-scale real-time tracking & dispatch system' provides an excellent, industry-aligned explanation of how streaming features are computed for pricing.
Please read this brief section. It explains how a stream processing engine like Flink is used to compute supply and demand counts per geographic cell (using H3, which we discussed in the last lesson).
Here's the pipeline:
- Geospatial Grid: The entire city is divided into a grid of hexagonal cells using Uber's H3 library.
- Event Streams: Two key event streams flow into Kafka:
- Supply: Location updates from all available drivers.
- Demand: Ride requests originating from riders.
- Stream Processing: A Flink or Spark Streaming job consumes these streams. For each H3 cell, it maintains a running count of
available_driversandride_requestsover various time windows (e.g., last 1 minute, last 5 minutes, last 15 minutes). - Feature Store: These computed supply/demand ratios for each cell are written to a low-latency feature store (e.g., Redis, Pinot).
- Pricing Service: When calculating a fare, the Ride Service queries this feature store for the current supply/demand ratio in the rider's pickup H3 cell. If the ratio is below a certain threshold, it applies a surge multiplier to the base fare.
This mechanism allows the system to react to marketplace imbalances in near real-time, forming the core of the surge pricing algorithm.
4. Deep Dive 2: The Matching Process
Once the rider confirms the ride, the central task is to match them with a driver. This process has two main challenges: finding nearby drivers efficiently and ensuring the assignment is consistent.
A. Finding Nearby Drivers (Proximity Search)
The first step is to answer: "Which drivers are available near the rider?" As we learned in the last lesson, scanning a database of millions of drivers is not feasible. We need a specialized geospatial index.
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
Let's revisit the mock interview, which contains an excellent deep dive on the trade-offs for the location database that powers this proximity search. This is one of the most important parts of the design.
Please watch from 34:34 to 45:30. This is a masterclass in comparing different technologies for a specific use case. The speaker analyzes: Postgres (naive): Why B-Tree indexes are wrong for 2D data. Postgres with PostGIS (Quadtrees): Better, but struggles with the high write frequency of driver updates and re-indexing costs. Redis with Geohashing: The best fit, capable of handling hundreds of thousands of transactions per second with an in-memory index. This aligns perfectly with what we discussed for the traffic data pipeline.
The matching workflow for finding candidates is as follows:
- The Matching Service receives a ride request.
- It uses the rider's pickup coordinates to determine the current H3 cell.
- It queries the Location Service (backed by Redis with geohashing/H3) for all available drivers in that cell and its neighboring cells (a "k-ring" search).
- This returns a list of candidate drivers. This list is then ranked not just by proximity, but by a multi-objective function considering factors like driver rating, vehicle type, and predicted acceptance probability, as noted in the "Architecting an Uber-scale" article.
B. Ensuring Consistency (Preventing Double-Dispatch)
This is the most critical correctness problem in the matching system. Imagine two ride requests come in simultaneously, and the same driver is the closest candidate for both. If two different instances of the Matching Service try to assign this driver, you could end up with the driver being double-booked and one rider being left stranded.
The Problem: How do you coordinate across multiple distributed servers to ensure a driver is offered to only one ride at a time?
The Solution: Distributed Locking with Time-To-Live (TTL)
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
The mock interview provides a clear and practical solution to this classic distributed systems problem.
Watch the segment from 47:55 to 57:39. The speaker explains: The race condition that arises from multiple horizontally-scaled matching service instances. Why a simple database status field is insufficient without a way to handle timeouts. Why a cron job to clean up stale locks is suboptimal due to added latency. The final, robust solution: using a distributed lock (e.g., a key in Redis or a row in DynamoDB) with a short TTL that matches the driver's acceptance window (e.g., 15 seconds).
The process is as follows:
- When the Matching Service wants to offer a ride to
driver_123, it first tries to acquire a lock for that driver. It does this by attempting an atomicSETNX(set if not exists) command in Redis:SETNX lock:driver_123 <ride_id> EX 15. - If the command succeeds: The service has successfully reserved the driver for 15 seconds. It can now send the offer to the driver's device via a push notification service.
- If the command fails: Another process already holds the lock. The service immediately discards this driver as a candidate and moves to the next one on its list.
- The TTL is crucial. If the driver doesn't respond, the lock automatically expires after 15 seconds, making the driver available for other requests without any cleanup process.
This ephemeral lock pattern ensures atomicity and consistency in a high-throughput, distributed environment.
5. Handling High-Throughput Surges
What happens when a Taylor Swift concert ends and 50,000 people request a ride at once? Your backend services will be flooded. Even with auto-scaling, it might not be fast enough. This is where a message queue becomes essential.
Design Uber w/ a Ex-Meta Staff Engineer: System Design Interview breakdown
Finally, let's look at how to build resilience against massive, sudden spikes in traffic.
Watch from 57:39 to 01:01:31. This section explains how introducing a Ride Request Queue (like Kafka or RabbitMQ) in front of the Matching Service acts as a buffer. It decouples the request intake from the processing, allowing the system to absorb bursts and process them gracefully. The idea of partitioning the queue by region is also a key scalability pattern.
By placing a queue between the API gateway and the Matching Service, you create a shock absorber. Requests are safely stored in the queue, and the matching services can pull from it at a sustainable rate, preventing them from being overloaded and crashing.
Conclusion
In this lesson, we designed a complete, Staff-level ride-sharing system. We built upon our previous design for navigation and ETA and integrated it into a larger architecture.
Key Takeaways:
- System Decomposition: A complex system like Uber is broken down into specialized services: a Ride Service for business logic, a Navigation Service for routing, a Location Service for geospatial data, and a Matching Service for driver assignment.
- Surge Pricing: Dynamic pricing is achieved by treating supply (driver locations) and demand (ride requests) as real-time event streams, processing them with tools like Flink to compute supply/demand ratios for geographic cells.
- Efficient Matching: Finding nearby drivers at scale requires a specialized in-memory geospatial index (e.g., Redis with H3/Geohashing) to handle the high write throughput of location updates.
- Consistency in Matching: Preventing double-dispatch is solved using a distributed lock with a TTL, an essential pattern for ensuring correctness in a distributed environment.
- Scalability under Load: Sudden traffic spikes are managed by introducing a request queue, which decouples ingestion from processing and prevents system overload.
Preview of the Next Lesson:
We've now completed your requested deep dives into systems at Google (Web Crawler), Uber (Navigation and Ride-Sharing), and will soon tackle DoorDash (Food Delivery). In the next lesson, we will shift focus to another major company: Meta. We will design a news feed system, which presents a different set of challenges related to data fan-out, ranking, and real-time updates.