Design a Cab Booking and Driver Matching System

Problem

Design an OOP model for Ola's cab booking and driver matching system.

Requirements

  • requestRide(riderId, pickupLoc, dropLoc, rideType) → rideId
  • matchDriver(rideId) → assigns nearest available driver of correct vehicle type
  • acceptRide(driverId, rideId) / rejectRide(driverId, rideId)
  • startRide(rideId) → completeRide(rideId, actualFare)
  • cancelRide(rideId, cancelledBy) — different cancellation policies

Key classes

Rider, Driver, Ride, Location, PricingEngine, MatchingEngine

Design decisions

  • Driver state machine: offline → available → en_route → on_trip
  • Spatial indexing for nearest driver lookup (geohash grid)
  • Pricing strategy pattern (regular, surge, share)

Extension

Add ride-sharing: match two riders going in the same direction.

added …
LeaderboardSalaryAccount