System Design advanced LIVE SIMULATOR
πŸš—

Ride-Sharing Service (Uber/Lyft)

Explore geospatial indexing (Geohash vs QuadTree), real-time driver coordinates streaming, surge pricing dynamic feedback loops, and transactional trip matching states.

system designgeospatial indexingredis geosurge pricingstate machinereal-time streamingsimulator
Interactive Simulator

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

A ride-sharing system is a real-time matching market. Drivers stream their GPS coordinates to a geospatial index, riders request trips, and the dispatcher queries for nearby available drivers, applies surge pricing when demand outstrips supply, and pairs a rider with the nearest available driver inside the configured radius.

Mental Model

At its core, a ride-sharing system is a real-time matching market. Drivers stream their GPS coordinates continuously to a high-performance database. When a rider requests a trip, the dispatcher must instantly query the database for nearby available drivers. If demand exceeds supply, a surge pricing engine raises fares to suppress low-priority demand and attract nearby drivers. The matching is solved using bipartite matching algorithms to pair drivers and riders efficiently, while a trip manager coordinates payment, pickup, and navigation states.

Components and Why They Exist

Rider App

Represents the client requesting rides. Queries the Surge Engine for dynamic fares and queues a matching request. In the demo, observe requesting a ride queue a matching request and fetch active surge multipliers.

Driver App (Driver A & B)

Represents vehicles online on the road. Streams GPS updates to the location index and receives ride offers. In the demo, watch how drivers accept or reject requests and stream GPS updates.

Dispatcher Service

The core matchmaking coordinator. Pulls pending requests from the queue and queries the location index to find the optimal driver. In the demo, watch the Dispatcher query available drivers and offer the nearest candidate.

Redis Geo Index

Horizontal geospatial database index. Stores active driver locations and serves low-latency radius query requests. In the demo, notice that toggle between Geohash (Z-order grid indexing) and QuadTree (recursive space partitioning) to see how coordinates are indexed.

Surge Pricing Engine

Rebalances local supply and demand dynamically. Recalculates dynamic fare multipliers based on the supply/demand ratio in localized spatial cells. In the demo, watch the surge multiplier rise when demand spikes or drivers go offline.

Trip Manager

Tracks state machine status for the lifecycle of a trip. Drives the trip through REQUESTED, MATCHED, PICKING_UP, EN_ROUTE, and COMPLETED states, handling cancellations. In the demo, note status updates and state changes of trips under matching operations.

Billing System

Decouples payment execution from the dispatch pipeline. Transactionally bills riders upon trip completion, ensuring payment success. In the demo, observe billing transactions executing once trips land in a completed state.

Edge Cases and Misconceptions

Geohash Boundary Issue

Geohashes use static cells. A rider and a driver can be only 10 meters apart but on opposite sides of a geohash boundary line, meaning they belong to different geohash strings. To prevent this, dispatchers query not just the target cell, but also all 8 surrounding neighbor cells.

Surge Pricing Supply Lag

Surge pricing is a reactive feedback loop. Raising prices attracts drivers to a high-demand zone, but it takes time for drivers to physically navigate there. During this lag window, surge multipliers can remain high.

Greedy Matching Inefficiencies

Matching the first available driver to a rider is called greedy matching. While fast, it can create a cascading bottleneck where subsequent riders are matched with far-away drivers. Batching requests over 2-3 second intervals and optimizing them globally reduces average ETAs significantly.

Common Questions

How does geospatial matching work in a ride-sharing system?

Geospatial matching uses dynamic location indexes like Redis Geo or coordinate-based grids. When a rider requests a trip, the service queries the index for available drivers within a specific radius (e.g., 5 miles) and selects the nearest available driver within the configured matching radius.

What is the difference between Geohash and QuadTree indexing?

Geohash splits the Earth into static grid cells mapped to string codes using a Z-order space curve, whereas a QuadTree dynamically subdivides quadrants into smaller sub-quadrants once a region's density (such as active drivers/restaurants) exceeds a threshold, making it more adaptive to rural versus dense urban environments.

How is dynamic surge pricing computed in real-time?

Surge pricing is computed by dividing the number of ride requests (demand) by the number of active, available drivers (supply) within a specific spatial cell over a temporal window. If the ratio exceeds 1.0, the surge engine applies a dynamic multiplier to adjust fares, balancing the market by encouraging drivers to log in and throttling excess demand.

How do ride-sharing systems handle driver coordination at high scale?

The simulator keeps the coordination path explicit: drivers publish GPS updates to Redis Geo, and the Dispatcher queries available drivers within the configured radius. Production systems can partition these updates or add asynchronous queues, but those scaling layers are outside this walkthrough.

What does the simulator’s nearest-driver matcher demonstrate?

The simulator chooses an available driver nearest to the rider, then records the offer and trip state. This is intentionally a greedy, inspectable path; production systems may optimize several requests together, but that batch algorithm is not executed here.