KatInterview

Design a Multi-Location Book Reservation & Inventory System

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemsconcurrency

Last updated

Architect a distributed inventory, reservation, and circulation platform across multiple physical locations with transactional guarantees, idempotency, and search index synchronization.

Architect a backend system for a multi-branch public library network. While every library branch stores and manages its local physical inventory, users must be able to search the global catalog, discover item availability per branch, and reserve or check out books seamlessly.

Requirements

Functional Requirements

  1. Unified Search: Users can search titles across the entire library network and view real-time availability broken down by branch.
  2. Holds & Reservations: Users can place a hold on an available copy at a target branch, preventing double-booking and locking the copy until checkout or hold expiration.
  3. Circulation Workflow: Support state transitions for physical copies: AVAILABLE $\rightarrow$ RESERVED $\rightarrow$ CHECKED_OUT $\rightarrow$ AVAILABLE (upon return).
  4. Branch Ownership & Tracking: Maintain tracking of where each physical copy belongs and its current state across the network.

Non-Functional Requirements

  1. Strict Concurrency Control: Guarantee strong consistency for physical copy state transitions. Prevent race conditions where multiple users attempt to reserve or check out the last available copy concurrently.
  2. High Availability vs. Consistency Trade-off: The system must degrade gracefully during network partitions or search index lag while keeping reservation/checkout operations strongly consistent.
  3. Idempotent Operations: Network timeouts and retry attempts by clients (or branch barcode scanners) must not cause duplicate state updates or secondary side-effects.
  4. Fault Tolerance: Ensure side-effects (e.g., audit logging, user notifications, search indexing updates) do not corrupt transactional state if downstream components experience mid-operation failures.

Hints

Hint 1

Distinguish between read-heavy search requirements (tolerates eventual consistency) and write-heavy item state transitions (requires strong consistency).

Hint 2

Use database-level locking mechanisms like SELECT ... FOR UPDATE SKIP LOCKED for concurrent item reservations to avoid race conditions.

Hint 3

Implement the Transactional Outbox pattern to reliably bridge relational database state updates with downstream event streams (Kafka/Search Indexers).