Katkat

Design a restaurant reservation system

GrammarlySoftware Engineer · Technical Screen

Last updated

This question assesses the ability to design a distributed reservation system that handles high concurrency, prevents double-booking, and ensures data consistency.

Problem Statement

Design a scalable restaurant reservation system that allows users to view restaurant availability and book tables. The system should handle concurrent booking requests to ensure that no table is double-booked.

Functional Requirements

  1. Users can search for restaurants based on location, cuisine, and time.
  2. Users can view available time slots for a specific restaurant.
  3. Users can reserve a table for a specific number of guests at a chosen time.
  4. Users can cancel existing reservations.

Non-Functional Requirements

  1. High consistency is required for the booking process to prevent double-booking.
  2. The system should be able to handle bursts of traffic (e.g., during peak dining hours).
  3. Low latency for search queries.

Scope

Provide a high-level architecture including:

  • API interface (endpoints for search, reservation, and cancellation).
  • Database schema design (consider how to handle table availability states).
  • Strategies for concurrency control (how to prevent two users from booking the last available table at the same time).
  • Infrastructure components (load balancing, caching, and storage choices).

Hints

Hint 1

Consider the difference in read/write patterns: search queries will be frequent, while reservations are write-heavy and require strict transaction guarantees.

Hint 2

Think about how to lock a specific table state during the 'reservation' flow to ensure atomicity, using database-level row locks or distributed locks.

Hint 3

For scalability, consider how to partition or shard your data—would you shard by restaurant ID or by geographic region?

Follow-up questions

  • How would you handle a scenario where a user is in the middle of a booking flow but their network disconnects before they confirm?
  • If the system suddenly experiences a massive spike in traffic, how would you prevent the database from being overwhelmed by reservation attempts?
  • How would you implement a notification service to remind users of their upcoming reservations without coupling it tightly to the booking service?