EN 中文

System Design Lab

Ride matching is bound by ingesting high-frequency driver GPS and answering nearest-driver queries fast, not by request volume.

Tune how many drivers are online, how often each one reports GPS, the ride-request rate, the search radius, and how many cities you serve. The design moves from one service to a dedicated location-ingest path, an in-memory geospatial index for nearest-driver queries, a durable trip-state store, and per-geo sharding with surge pricing.

Guided walkthrough

Reason about it one step at a time

Normal evolution scenarios

Click left to right for the intended demo path. Each card changes the workload inputs.

Workload

These are inputs, not preset architecture stages.

Recommended shape

Current architecture path
Ride-sharing matching architecture diagram Whiteboard-style architecture diagram for ride matching: drivers and riders, a location-ingest path and API gateway, an in-memory geospatial index with a matching service, a durable trip-state store, and an async pricing and analytics pipeline. Clients Ingest / gateway Geo + matching Trip state Pricing / analytics Driver app GPS stream Rider app requests rides API gateway rider requests Location ingest high write rate Geo index in-memory cells Matching service pairs + state Trip-state store state machine Geo shards by city / cell Surge engine demand / supply Event stream async events
Clients
Driver app reports its location every few seconds while online
Rider app asks to be matched with the nearest available driver
Ingest / gateway
API gateway authenticates riders and routes match requests to the matching service
Location ingest absorbs the firehose of driver GPS updates and feeds the geo index
Geo + matching
Geo index keeps live driver positions in geohash/quadtree/S2 cells for nearest queries
Matching service queries the index for candidates and pairs a rider to a driver
Trip state
Trip-state store durably tracks each trip from requested to matched to en route to complete
Geo shards partitions drivers and trips by geography so each region scales independently
Pricing / analytics
Surge engine computes per-area surge multipliers off the hot matching path
Event stream collects trip and location events for analytics and ML offline

Bottlenecks

Location write throughput

Geo-query load

Geo-index memory

Matching + trip-state QPS

Cross-city / shard pressure

Why this changes

    Decision tradeoffs

    Location ingest path

    Geospatial index

    Matching service

    Trip-state store

    Surge pricing engine

    Shard by city / geo

    Source-backed rules

    These are the durable system-design claims behind the model. The exact slider thresholds are deliberately labeled as teaching assumptions.

    Verified rule

    Uber matches riders to drivers using S2 geospatial cells

    Uber indexes the world with hierarchical cells (H3, building on Google S2) so nearest-driver lookups become bounded scans over a small set of cells.

    Uber Engineering
    Verified rule

    Geohashing turns proximity search into prefix range scans

    Encoding lat/long as a geohash lets nearby points share a prefix, so a radius query becomes a small set of in-memory sorted-set range reads.

    Redis Docs
    Verified rule

    High-frequency location ingest is a write-heavy streaming problem

    A continuous flood of per-driver GPS events is best absorbed by a partitioned log that decouples ingest from the index and downstream consumers.

    Apache Kafka
    Verified rule

    Quadtrees answer 2D nearest-neighbour queries efficiently

    A quadtree recursively subdivides space so a region query only visits the cells that overlap the search area instead of every point.

    Wikipedia

    Teaching assumptions

    • Location ingest write rate is modeled as active drivers times GPS update frequency; real systems batch and dedup updates.
    • Single-node ingest, geo-query, and trip-state budgets are conservative teaching numbers, not vendor limits.
    • Geo-query cost grows with search radius and cell density; the in-memory index memory scales with active drivers.