Car Rental System

Vehicle Rental Management Platform

Design a car rental system that books cars by category and date range across branches, supports one-way rentals and maintenance blocks, never double-books a car, and bills at return.

Overview

A rental company has branches, each with cars in a few categories. A customer asks for a category, a pickup branch, a return branch and a date range. The system must find a car that is free for the whole range and will be at that branch when the rental starts, hold it, and later bill the customer for what they actually used.

What makes this harder than a parking lot is time. A car is not simply free or taken: it is free on some days and booked on others, and after a one-way rental it sits at a different branch. The interviewer is listening for three things: an overlap test for date ranges that you can state in one line, a schedule per car that answers 'can this car take this booking?' atomically, and a clear life cycle for a reservation with the illegal moves refused.

Scoping the problem

Ask these questions first, because each answer changes the design. Each comes with the answer most interviewers accept.

  • Does the customer book a category or a specific car? This decides what search returns. Usually a category, and the system picks the car.
  • What is the time unit? Hours make the overlap math the same but the numbers bigger. Usually whole days.
  • Are one-way rentals allowed? Then the car's location changes over time. Usually yes, with a fee.
  • How are cars taken out for service? That is another thing that occupies a car's schedule. Usually with a maintenance block on the car's schedule.
  • How is the price made up? This is the part that changes most. Usually a daily rate by category, a weekly discount, add-ons, late days and a one-way fee.
  • Do many agents book at once? Then two bookings must not win the same car. Usually yes, so booking is atomic per car.
  • What about payments, licenses and loyalty? They are separate services, so they are out of scope.

Functional requirements

  • reserve(customer, category, pickup, dropoff, start, end, add_ons) picks a car of the category that is free for [start, end), is at the pickup branch at start, and does not break its next booking
  • One-way rentals: the car is at the dropoff branch after the rental ends
  • block_for_maintenance(car, start, end) occupies the car's schedule at its current branch
  • cancel frees the car; pick_up and return_car move the reservation through its states
  • return_car(rid, day) returns a bill: rental, weekly discount, add-ons, late days, one-way fee, total
  • Illegal moves (return twice, cancel after pickup) are refused

Non-functional requirements

  • A car is never booked for two overlapping stays, even when many agents book at once
  • Booking locks one car at a time; different cars never wait on each other
  • Pricing rules change by adding or swapping a PricingStrategy, not by editing the service
  • Days and money are integers, so tests are exact

Interview questions

  • Two agents book the last SUV for the same dates at the same moment. What happens?
  • A customer returns the car two days late, and the car was booked by someone else for the next morning. How do you handle it?
  • How would you send cars for service every N miles?
  • Search is slow with thousands of cars. How do you speed it up?

Sign up free to read the full topic

More Low-Level Design topics

Start free on Cariara · Coding problems · System design studio