Back to LLD explorer
Proximity / Dispatch Patterns: Observer, Strategy

Uber

Hard

Problem Summary

Design the class system for Uber/Lyft matching rider queries to optimal local drivers in real-time.

Functional Scope

  • Riders input source and destination coordinates to request trip.
  • Find closest active driver within N miles (e.g. using spatial matching).
  • Dynamic trip pricing strategies (surge based on active trip demand/drivers count).

Entity-Relationship (ER) Schema

Rider [1] <---> [*] Trip
Driver [1] <---> [*] Trip
Trip [1] <---> [1] Location (Start)
Trip [1] <---> [1] Location (End)

Design Approach

Match drivers using spatial grid grids (like geohash/S2 cells). Decouple surge calculations into Strategy patterns for easy live testing overrides.

Core Classes & Models

Rider & Driver (Actor models)Trip (Source, Destination, Driver, Rider, Fare, Status)Dispatcher (Coordinates vehicle assignments)
Code Blueprint
public class Trip {
    private String tripId;
    private double fare;
    public void setFare(double f) { this.fare = f; }
}