Design Uber (Ride-Hailing System)
Requirements: Design a ride-hailing system like Uber: riders request a ride from a pickup to a drop location, nearby available drivers are matched, the trip is tracked in real time, and a fare is calculated at the end.
Design: Core components: a Location Service ingesting frequent GPS pings from driver apps (via a message queue for scale), a geospatial index (geohash/quad-tree/S2) to quickly find nearby available drivers for a ride request, a Matching Service that assigns the best driver (balancing proximity, ETA, and driver idle time) and handles accept/reject/timeout, a Trip Service tracking state (Requested -> Accepted -> In Progress -> Completed), and a Pricing Service computing fare (base + distance/time + surge multiplier from a Surge-Pricing Service that monitors demand/supply imbalance per zone). Discuss trade-offs in matching (nearest driver vs least-idle driver for fairness), how to keep location updates scalable (batching, using a pub-sub layer so only relevant regional subscribers get updates), and handling driver/rider disconnects mid-trip.