KatInterview

Design a Time-Interval Vehicle Booking System

System DesignModel answer
MediumModel answerSystem Designconcurrencyinventory-managementdistributed-systems

Last updated

Design a booking service for rental vehicles: availability search, temporary holds, confirmation, cancellation, concurrency control, and double-booking prevention.

Design a Time-Interval Vehicle Booking System

Background

A vehicle rental platform lets customers find and reserve cars at various locations. A customer picks a location, specifies a pickup and return window, browses available vehicles, places a hold, and then either confirms or abandons it. Because the fleet is finite, multiple customers may race to claim the same car or the last car in a given class.

What to Design

Describe the system end to end:

  • APIs — what endpoints exist, what they accept, and what they return
  • Data model — how vehicles, availability, holds, and confirmed reservations are stored
  • Availability search — how the system finds vehicles free during a requested interval
  • Hold and confirmation flow — the lifecycle from search result to confirmed booking
  • Concurrency control — how the system guarantees no vehicle is double-booked
  • Degraded inventory handling — what happens when the item a customer holds is no longer available by the time they confirm

Key Question

Search results are inherently advisory — they reflect a snapshot that may already be stale. At exactly which step must the system enforce that the vehicle is still free, and what mechanism makes that enforcement safe?

Constraints and Assumptions to Address

  • A single vehicle cannot be committed to two overlapping bookings.
  • Holds that are never confirmed must expire automatically and release inventory.
  • Clients and background workers may retry any request; the system must behave correctly under retries.
  • Availability search may return slightly stale data, but a confirmation must never produce a double-booking.
  • State whether a customer books a specific vehicle or a vehicle class, and justify the choice.

Clarifying Questions Worth Raising

  • Are customers booking an exact car (by plate or ID) or any car within an equivalent class?
  • Can pickup and return happen at different locations, and how does that affect fleet availability modeling?
  • How long is a hold valid, and can a customer extend it?
  • When the last vehicle in a class is taken, does the system offer a waitlist, an upgrade, or simply a rejection?

Hints

Hint 1

Start with the reservation state machine: sketch every state a booking can be in (e.g., SEARCHING, HELD, CONFIRMED, CANCELLED, EXPIRED) and every valid transition before touching APIs or storage.

Hint 2

The hardest constraint is atomic inventory claim. Think about how a relational database row-level lock or an optimistic-concurrency version check lets you detect a conflict at the exact moment of hold creation — not at search time.

Hint 3

Hold expiry is an inventory leak if not handled. Consider a background sweeper versus a lazy expiry check on read, and think about what happens to in-flight confirmation requests when a hold expires mid-flight.