KatInterview

Reservation Service Design: REST Endpoints, Schema, Date Inventory

System DesignModel answer
MediumModel answerSystem Designrest-apischema-designinventory-modeling

Last updated

Design a REST API and database schema for booking a stay or rental, compare per-day and interval inventory models, and support extending an existing reservation.

You are designing the backend for a service where a customer reserves a single bookable resource (a room, a vehicle, a rental unit) for a span of time.

Part 1: API and data model

Design a RESTful API that lets a customer:

  • Search for what is available in a given time window.
  • Create a reservation.
  • View and cancel a reservation.
  • Pay for and confirm a reservation, if your design needs that step.

For each endpoint, describe:

  • The path and HTTP method.
  • The shape of the request and response.
  • The important status codes, including the failure cases.

Then describe the data model: tables or collections, key fields, and the indexes you would add and why.

Part 2: Two ways to model inventory

Describe and compare two designs for tracking availability:

  1. Per-date inventory: one record per resource per day.
  2. Interval-based inventory: one record per reserved or blocked time range.

Discuss correctness under concurrent requests, storage cost, time granularity, pricing, and search performance. State which you would choose and why.

Part 3: Follow-up

Add support for extending an existing reservation, for example moving the end date later. What changes in the API and in the data model? Consider conflicts with the next reservation, pricing, payment, and concurrent edits.

State any assumptions you make, such as scale and consistency needs.

Hints

Hint 1

Decide first whether each resource is a single unit (one car, one cabin) or a pool of identical units (hotel room types). It changes how you prevent double-booking.

Hint 2

Treat reservation creation as a state machine (pending, confirmed, canceled, expired) with a hold that expires, and make mutating calls idempotent with a client-supplied key so retries do not duplicate bookings or charges.

Hint 3

For the extension, model it as a conditional change to the end of the existing range: check only the added slice for conflicts, charge only the difference, and use a version number to detect concurrent edits.