🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Design Uber

System Design ProblemsReal-Time Systems🟢 Free Lesson

Advertisement

System Design Problems

Design Uber

Uber serves 100M+ monthly active users across 70+ countries with real-time ride matching, location tracking, and dynamic pricing. This design covers geospatial indexing, dispatch systems, and ETA estimation.

  • Scale — 100M+ MAU, 19M trips/day, 5M+ drivers
  • Latency — Driver matching < 5 seconds
  • Real-time — Location updates every 4 seconds

Uber's core challenge is solving the real-time matching problem at global scale with sub-second latency.

Requirements Clarification

Functional Requirements

  1. Request a ride and get matched with a driver
  2. Real-time driver location tracking
  3. ETA calculation for pickup and dropoff
  4. Dynamic pricing (surge pricing)
  5. Trip management (start, end, payment)
  6. Driver availability management
  7. Rating system for riders and drivers

Non-Functional Requirements

  1. Availability: 99.99% uptime
  2. Latency: Match driver < 5 seconds
  3. Consistency: Strong for location, eventual for payments
  4. Scale: 5M concurrent drivers, 100K ride requests/minute

Uber's key insight: Location data is the core primitive. Everything else (matching, routing, ETA) depends on efficient geospatial indexing and real-time location processing.

Back-of-the-Envelope Estimation

Location Update Rate

QPSlocation=5M×1 update4 sec=1.25M QPS\text{QPS}_{\text{location}} = \frac{5M \times 1 \text{ update}}{4 \text{ sec}} = 1.25M \text{ QPS}

Here,

  • 5M5M=Concurrent drivers
  • 4sec4 sec=Update interval
  • 1.25M1.25M=Location QPS

Storage Estimation

Location data per driver per day:

  • 1 update/4 sec x 86400 sec = 21,600 updates/day
  • Each update: 50 bytes (lat, lng, timestamp, driver_id)
  • Per driver: 21,600 x 50 = 1.08 MB/day

Total daily location data: 10M drivers x 1.08 MB = 10.8 TB/day

High-Level Architecture

Rider/DriverAPI Gateway / Load BalancerTrip SvcMatching SvcLocation SvcPricing SvcRoute SvcPayment SvcEvent Bus (Kafka)Redis (Location)S2 GeometryPostgreSQLHBase (Trips)Kafka (Events)

Geospatial Indexing: S2 Geometry

DfS2 Geometry

S2 is Google's spherical geometry library that divides the Earth's surface into hierarchical cells. Uber uses S2 cells at level 15 (~1km x 1km) for driver indexing. This enables efficient range queries for finding nearby drivers.

S2 Cell Lookup

cell_id=S2.latLngToCellID(lat,lng,level=15)\text{cell\_id} = S2.\text{latLngToCellID}(lat, lng, level=15)

Here,

  • lat,lnglat, lng=Latitude and longitude
  • level=15level=15=Cell resolution (~1km)
  • cellidcell_id=64-bit cell identifier

S2 cells provide O(1) lookup for "find drivers in this cell." For nearby cell queries, we check the 8 neighboring cells. This is much faster than brute-force distance calculations.

Matching Algorithm

Rider RequestFind Nearby DriversRank by ScoreDispatch Offer

Driver Score

Score=w11ETA+w2rating+w3(1surge)\text{Score} = w_1 \cdot \frac{1}{\text{ETA}} + w_2 \cdot \text{rating} + w_3 \cdot (1 - \text{surge})

Here,

  • ETAETA=Estimated time to pickup
  • ratingrating=Driver rating (0-5)
  • surgesurge=Current surge multiplier

Surge Pricing

DfDynamic Pricing

Surge pricing is determined by supply-demand ratio in real-time. When demand exceeds supply in a region, prices increase to balance the market. The surge multiplier is calculated every minute for each S2 cell.

Surge Calculation

surge=max(1,demandsupply×α)\text{surge} = \max(1, \frac{\text{demand}}{\text{supply}} \times \alpha)

Here,

  • demanddemand=Ride requests in last 5 min
  • supplysupply=Available drivers in cell
  • alphaalpha=Calibration constant

Trip State Machine

REQUESTEDMATCHEDARRIVINGIN_PROGRESSCOMPLETEDCANCELLED

Data Model

Trip Schema

Trip=(trip_id,rider_id,driver_id,status,pickup,dropoff,fare,timestamp)\text{Trip} = (trip\_id, rider\_id, driver\_id, status, pickup, dropoff, fare, timestamp)

Here,

  • tripidtrip_id=Unique trip identifier
  • pickup/dropoffpickup/dropoff=S2 cell + coordinates
  • statusstatus=State machine state

Practice Exercises

  1. Geospatial: Design a system to find all drivers within 5km of a rider. What data structure would you use?
  2. Matching: How would you handle the case where a driver rejects a ride offer? Design the retry logic.
  3. Surge: Design a surge pricing algorithm that doesn't frustrate riders but balances supply/demand.
  4. Scale: How would you handle 10x traffic during New Year's Eve?

Key Takeaways:

  • S2 Geometry provides efficient geospatial indexing for driver lookup
  • Matching uses a scoring function balancing ETA, rating, and surge
  • Surge pricing balances supply/demand using real-time ratio calculation
  • Trip state machine manages the full lifecycle
  • Location updates are the core data stream (1.25M QPS)

What to Learn Next

-> Design Airbnb Marketplace and booking systems.

-> Design Amazon E-commerce at scale.

-> Design WhatsApp Real-time messaging systems.

-> Design Leaderboard Sorted sets and ranking.

-> Saga Pattern Distributed transactions.

-> Idempotency Handling duplicate requests safely.

Premium Content

Design Uber

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement