Uber Ride Sharing System¶
Quick Reference Guide for System Design Interviews
Problem Statement¶
Design a ride-sharing platform like Uber that matches riders with nearby drivers, handles real-time location updates, and processes trip requests at scale.
Requirements¶
Functional Requirements¶
- Rider requests a ride
- Match with nearby available drivers
- Real-time driver location tracking
- Trip fare calculation
- Payment processing
- Rating system
- Trip history
Non-Functional Requirements¶
- Latency: < 1s for driver matching
- Availability: 99.99%
- Scale: 100M users, 15M trips/day
- Location Updates: Every 3-4 seconds per driver
Back of Envelope Estimation¶
High-Level Architecture¶
Geospatial Indexing¶
Location Service¶
Trip Matching¶
Trip Lifecycle¶
Fare Calculation¶
Data Models¶
-- Drivers table
CREATE TABLE drivers (
driver_id UUID PRIMARY KEY,
name VARCHAR(100),
phone VARCHAR(20),
vehicle_id UUID REFERENCES vehicles(id),
status ENUM('offline', 'available', 'on_trip'),
rating DECIMAL(3,2),
total_trips INT DEFAULT 0,
created_at TIMESTAMP
);
-- Trips table
CREATE TABLE trips (
trip_id UUID PRIMARY KEY,
rider_id UUID NOT NULL,
driver_id UUID,
status VARCHAR(20),
-- Locations
pickup_lat DECIMAL(10, 7),
pickup_lng DECIMAL(10, 7),
dropoff_lat DECIMAL(10, 7),
dropoff_lng DECIMAL(10, 7),
-- Trip details
distance_miles DECIMAL(6, 2),
duration_mins INT,
-- Pricing
base_fare DECIMAL(10, 2),
surge_multiplier DECIMAL(3, 2) DEFAULT 1.0,
total_fare DECIMAL(10, 2),
-- Timestamps
requested_at TIMESTAMP,
accepted_at TIMESTAMP,
started_at TIMESTAMP,
completed_at TIMESTAMP,
INDEX idx_rider (rider_id, requested_at),
INDEX idx_driver (driver_id, requested_at)
);
-- Real-time location (Redis)
-- HSET driver:123:location lat 37.7749 lng -122.4194 timestamp 1705312200
-- SADD drivers:available:geohash:9q8yy driver:123
Real-time Communication¶
Interview Discussion Points¶
- How do you find nearby drivers efficiently?
- Geohash or QuadTree indexing
- Query current + neighboring cells
-
Filter by distance and availability
-
How do you handle 500K location updates/second?
- In-memory (Redis) for current locations
- Batch writes to persistent storage
-
Geo-sharding by region
-
How does surge pricing work?
- Supply/demand ratio per zone
- Real-time computation
-
Multiplier shown before booking
-
How do you ensure trip matching is fair?
- First-come-first-served for riders
- Rotate drivers to avoid starvation
-
Consider acceptance rate
-
How do you handle driver going offline during trip?
- Heartbeat detection
- Auto-reassign if no response
-
Edge cases for accidents
-
How do you scale globally?
- Regional deployments
- City-level data isolation
- Geo-routing at DNS level