Contents
Ride Lifecycle
Complete workflow from ride request to completion, including dispatch, tracking, and fare settlement.
Status Flow
requested --> dispatched --> accepted --> arriving --> in_progress --> completed
| | |
v v v
no_driver (timeout) cancelled
| re-dispatch
v
retry
1. Ride Request
A ride begins when a rider submits a request through the API.
RideHelper::requestRide() handles:
- Validates rider identity (CRM contact or guest)
- Generates unique ride reference (TX + hex)
- Detects pickup and dropoff zones via ZoneHelper::detectZone()
- Captures current surge multiplier from pickup zone
- Creates ride record with status
requested - Triggers dispatch process
Key design decision: the surge multiplier is captured at request time and stored on the ride record. This prevents the fare from changing between request and completion if surge conditions change during the ride.
2. Dispatch
DispatchHelper::dispatchRide() finds and offers the ride to nearby drivers.
- Uses bounding box SQL pre-filter to find drivers within radius
- Calculates haversine distance for precise filtering
- Sorts by distance (nearest first)
- Offers ride to closest available driver
- Creates dispatch record with status
offered - Sets ride status to
dispatched
If the driver does not respond within the configured timeout, the dispatch expires and the system offers to the next nearest driver.
See Dispatch Engine for full details.
3. Driver Acceptance
When a driver accepts:
- Dispatch record updated to
accepted - Ride status changes to
accepted - Driver and vehicle assigned to ride record
- ETA calculated based on driver location
4. Arriving
Driver location updates trigger proximity checks. When the driver is near the pickup location, the status changes to arriving.
5. In Progress
The ride begins when the driver confirms pickup:
- Status changes to
in_progress - Route tracking begins (polyline recording)
- Distance and duration timers start
6. Completion
RideHelper::completeRide() handles ride finalization:
- Captures final distance and duration
- Calls FareHelper::calculateFare() with:
- Actual distance traveled
- Actual duration
- Vehicle type
- Pickup zone ID (stored at request time)
- Surge multiplier (stored at request time)
- Breaks down fare into components (base, distance, time, surcharges)
- Calculates driver payout and platform fee
- Updates ride status to
completed - Updates driver statistics (total rides, earnings, rating)
7. Cancellation
Rides can be cancelled at any point before completion:
- By rider: free within cancellation window, fee after
- By system: if no driver available after all dispatch attempts
Retry Logic
If all available drivers reject or time out:
- Ride status set to
no_driver - Rider notified
- Rider can retry, which restarts dispatch with a fresh driver search