Design a car rental 00:00:00 Make a prediction You will separate a future class reservation from a concrete vehicle assignment and include maintenance in capacity decisions. A fleet lists three compact cars. One is in repair and two are already promised on Friday. How many additional compact reservations can Friday accept without overbooking? Zero for that interval under a no-overbooking policy. Counting vehicle records alone advertises inventory that cannot fulfill the promise. 00:00:32 Three boats, five people, one board A lakeside desk has three boats on a booking board. Promising a small boat next Friday is different from handing a particular repaired and inspected boat to the customer at pickup. A reservation protects class capacity across dates. A rental contract binds an actual vehicle and records condition, time and mileage. Maintenance removes capacity too. A car rental system makes promises about the future and keeps them at a counter. A promise is a size, a branch and a period. Keeping it means handing over one real car and getting it back. Nearly everybody starts with a flag isAvailable and finds out that it cannot answer anything about next week. The problem teaches that some facts are functions of time. 00:01:19 Reserve a class, then assign a car A customer reserves a compact car for Friday through Sunday. At booking time the system may promise the class rather than one registration number. At pickup, choose an available compact in acceptable condition and bind that specific vehicle to the rental contract. Returning the car records time, mileage and condition before it becomes available again. A late return affects future capacity even though the original reservation was valid. Take a compact reservation for Friday, then mark the initially expected car unavailable on Thursday. A promise of a class can still be honoured by assigning another suitable car. If the contract guaranteed that particular vehicle, the customer instead needs an explicit exception or replacement agreement. 00:02:08 Maintenance consumes capacity too A fleet has three compact cars, one in repair and two promised for Friday. The booking system must not advertise a third available compact just because it counts three vehicle records. Include operational unavailability in capacity decisions. Remove one of three vehicles for service across Friday and Saturday. Only two can fulfil overlapping compact reservations during that period. Returning the maintenance vehicle on Sunday should restore Sunday capacity without changing Friday's historical commitments. A unique constraint on vehicle identifier alone cannot express all overlapping future intervals or class-based reservations. Test overlapping and adjacent time windows. If a specialty vehicle is booked by exact registration, allocate that specific vehicle at booking instead of promising only its class. A database exclusion constraint can reject overlapping bookings for one named resource. That works naturally once a reservation specifies a particular vehicle. A reservation for any compact car asks a different question: how many overlapping commitments fit the fleet? Counting capacity safely needs a shared guard or another concurrency-safe allocation rule. 00:03:25 Try an interview follow-up Why is a unique constraint not enough in the database? The rule is about how many rows overlap, not about two equal rows. Two transactions each count one of two, insert different rows and commit: write skew. I need a guard that both touch: a parent row, the counters of the days, or serializable isolation with retries. An exclusion constraint helps only if a row names one car. A car returns one day early but has not been inspected. Can the service immediately sell that extra day of availability? Separate physical possession from readiness. If inspection is required, the car is returned yet unavailable until the inspection completes. A customer can receive the early-return acknowledgment without an unsafe promise to the next renter. 00:04:22 What to take with you A booking promises a size for a period and stores its rent. Free is fleet minus the peak of uses, each widened by the cleaning time, and the peak is found at the starts. Count and add are one step. At pick-up a ready car is chosen, upwards if needed and only if the calendar agrees. Late cars are busy now, early returns free the rest, a return is final before any money moves.