System Design Interview: A Car Rental Booking Platform
8 views
"Design a car rental system like Hertz or a peer-to-peer rental marketplace" combines inventory search across locations and dates, reservations without double booking, pricing, and the physical lifecycle of vehicles. Here is a structured approach for a 45-minute round.
1. Requirements
Functional: customers search for available cars by pickup location, dates, and car class; see prices; reserve; modify or cancel; pick up and return (possibly at a different location). Staff check cars in and out and mark them for maintenance.
Non-functional: search should be fast (under about 300 ms); a car must never be double booked; the system must handle holiday peaks; pricing can change frequently.
2. Key design decision: book by class or by specific car?
Traditional rental companies sell a car class at a location ("compact at the airport"), and assign a specific vehicle at pickup. Peer-to-peer platforms sell a specific car. Clarify which. For class-based booking, availability is a count: cars of that class expected at the location during the period minus existing reservations, plus a small overbooking buffer based on no-show rates.
3. Data model
- Locations, car classes, vehicles (VIN, class, home location, status: available, rented, maintenance).
- Reservations: customer, class or vehicle, pickup location and time, return location and time, status, price quote.
- Inventory projections: for each location, class, and day (or hour), the expected number of cars available, updated as cars are rented, returned, or moved.
4. Search
Precompute availability per location, class, and day into a fast store (a cache or a read-optimized table). A search over a date range checks the minimum availability across those days. For peer-to-peer, index cars by geolocation and use a calendar of booked intervals per car.
5. Booking without double booking
Use a transaction that checks and decrements availability atomically, either with row-level locks on the inventory rows for the affected days or with optimistic concurrency (a version number, retry on conflict). For specific-car bookings, enforce non-overlapping intervals per car with an exclusion constraint or a lock on that car's calendar. Hold inventory for a few minutes during checkout and release it if payment fails.
6. One-way rentals and fleet balancing
One-way returns shift inventory between locations. Update projections at the return location and run a batch job that recommends moving cars where demand forecasts exceed supply.
7. Pricing
Base rates per class and location, adjusted by demand, lead time, and length of rental. Lock the price at booking time by storing the quote on the reservation.
8. Pickup, return, and maintenance
Pickup assigns a vehicle, records mileage and fuel, and changes status. Return triggers inspection, damage notes with photos, final billing, and maintenance flags.
9. Trade-offs to discuss
Overbooking versus empty cars, cache freshness for search versus strict checks at booking, and how to handle late returns that conflict with the next reservation.
Getting help in the moment
Design interviews reward a steady structure. Linkjob AI (https://linkjob.ai) gives real-time help during live job interviews and technical interviews, reminding you of areas such as concurrency or failure handling while you lead your own design.