KatInterview

Build an In-Memory Venue Reservation Engine

System DesignModel answer
MediumModel answerSystem Designconcurrencyin-memorylow-level-design

Last updated

Design data structures and APIs for a reservation system that runs entirely in memory, handles concurrent bookings, and prevents double-reservations.

Build an In-Memory Venue Reservation Engine

You are building the core reservation engine for a chain of accommodations. There is no database — all state lives in memory for the lifetime of the process.

What you need to support

  • Register a property, define its room categories, and set how many rooms exist in each category.
  • Query which room categories have availability for a given arrival and departure date.
  • Place a reservation for one or more rooms of a given category.
  • Cancel an existing reservation and return those rooms to the available pool.
  • Guarantee that two concurrent requests for the last available room cannot both succeed.

Constraints and expectations

  • No external storage of any kind. Use only in-process data structures.
  • Before writing anything, state your assumptions clearly: how dates are interpreted, whether check-out day is considered occupied, your planning horizon, and what is out of scope.
  • Walk through the complexity of each operation. Justify your data structure choices.
  • Explain your concurrency strategy. Describe the granularity of your locks and why you chose it. Identify any deadlock risks and how you would avoid them.
  • You do not need to handle pricing or payments, but mention how you would extend the design if a payment hold step were added between search and confirmation.

What a strong answer looks like

A clear set of upfront assumptions, a data model with explicit reasoning, an API surface, a step-by-step explanation of how a booking is executed atomically, a comparison of at least two locking strategies with trade-offs, and a short code sketch of the critical booking path.

Hints

Hint 1

The hardest invariant to preserve is: available count never goes negative across every night in the requested range. Think about what 'atomic check-then-act' means in a multi-threaded context before picking a lock scope.

Hint 2

Storing a per-night integer counter per room category (rather than a list of bookings) makes availability checks a simple range-minimum scan and keeps memory usage predictable. Sketch the math: how many counters do you actually need?

Hint 3

When you hold multiple locks at once (e.g., booking two room categories in one transaction), you need a consistent acquisition order to avoid deadlock. What property of your data can you sort by?