MEDIUMReal-time Systemssenior engineer

Design Uber/Lyft

Design a ride-sharing application like Uber supporting real-time driver matching, location tracking, and fare calculation.

Estimated Time: 45 minutes
#ride-sharing#geospatial#real-time#matching#location
Solution Overview

Use geospatial indexing for driver matching, real-time location updates with WebSockets, and event-driven architecture.

Hints to Get Started
1

Think about geospatial data structures

2

How do you handle millions of location updates?

3

Consider surge pricing algorithms

Requirements

functional

  • Request ride
  • Match with driver
  • Real-time tracking
  • Fare calculation
  • Payments
  • Ratings

non functional

  • Low latency matching
  • High availability
  • Accurate ETA
  • Fraud prevention
Capacity Estimation

daily rides

20M rides/day

active drivers

5M drivers

location updates

5M drivers × 1 update/4s = 1.25M updates/second

High-Level Architecture

real time

geospatial

QuadTree or Geohash for proximity queries

driver location

WebSocket + Redis Pub/Sub

components

  • Ride Service
  • Matching Service
  • Location Service
  • Pricing Service
  • Payment Service
  • Notification Service
Deep Dives

surge pricing

Based on demand/supply ratio in geographic cells

eta calculation

Graph-based routing with real-time traffic

fraud detection

ML models for fake rides, GPS spoofing

Location Tracking

storage

Time-series DB for history, Redis for current location

ingestion

Kafka for high-throughput location updates

geospatial index

Update QuadTree as drivers move

Matching Algorithm

approach

  • Find nearby drivers using geospatial index
  • Filter by availability and rating
  • Calculate ETA for each
  • Rank by ETA and other factors
  • Send request to best match

data structure

QuadTree or S2 geometry library