Design a Ride-Pooling System (OLA Share)
HardReal World SystemsRoute OptimizationMatchingGeolocationCarpoolingReal-Time
Problem Statement
Design a ride-pooling system (like Ola Share or Uber Pool) where multiple passengers with similar routes share a single cab — reducing individual fares while maximizing driver utilization.
Requirements
Functional Requirements
- Passenger requests a pool ride: pickup, drop-off, max wait time
- System attempts to match with an existing pool ride going in a compatible direction
- If no match: create a new pool ride for that passenger
- Pool ride capacity: max 2–3 passengers per vehicle
- Fare: individually calculated based on each passenger's distance segment
- Driver picks up and drops off passengers in optimized route order
- Passenger can set maximum detour tolerance (e.g., route cannot increase by more than 20%)
- If all pool attempts fail within max wait time: auto-upgrade to solo ride
- Rating system for pool co-passengers (optional)
Non-Functional Requirements
- Thread-safe pool matching
- Singleton PoolingService
Key Entities
- PoolRequest: id, passenger, pickup, dropoff, maxWaitTime, maxDetour, status
- PoolRide: id, driver, passengerRequests, currentRoute, status, vehicle
- RouteSegment: start, end, distance
- MatchingEngine:
findCompatiblePool(PoolRequest)→ PoolRide or null - PoolingService: Singleton
Constraints
- Max 3 passengers per pool ride
- Detour tolerance: new passenger's addition cannot increase any existing passenger's travel time by > maxDetour%
- Pool matching window: 5 minutes; if no match, create new pool or upgrade to solo
- Thread-safe matching — concurrent pool requests must not overbook a ride
!Constraints
- Max 3 passengers per pool vehicle
- Detour check: adding new passenger must not increase existing passenger ETA by > maxDetour%
- Pool matching window: 5 minutes maximum
- Thread-safe: concurrent requests cannot assign same pool ride to >3 passengers
- Auto-upgrade to solo ride if no pool match within window
Output
Run or submit your code to see output here.