Movie Ticket Booking

Hardconcurrencydeadlockstate machineexpiry

Design the seat-booking core of a movie ticketing app. When a popular show opens, thousands of users try to grab the same seats.

Requirements

  1. Hold. hold(showId, seatIds, userId) reserves all the requested seats or none of them, and returns a hold id.
    • If any seat is booked, or held by a hold that hasn't expired, it throws SeatUnavailableException. After a failure, nothing is held.
    • An unknown show or seat throws NotFoundException.
    • A null or empty seat list, a seat repeated in one request, or a blank user id throws IllegalArgumentException.
  2. Expiry. A hold blocks its seats for holdTtl. It is expired once now >= createdAt + holdTtl, and its seats are free again without any background job. Read time only from the Clock passed to Solution.create.
  3. Confirm. confirm(holdId) turns the hold into a booking, and booked seats are never available again.
    • Confirming twice does nothing.
    • Confirming an expired hold throws HoldExpiredException.
    • Confirming a released hold throws InvalidStateException.
  4. Release. release(holdId) gives the seats back.
    • Releasing twice, or releasing an expired hold, does nothing.
    • Releasing a confirmed hold throws InvalidStateException.
  5. Query. availableSeats(showId) returns the seats that are neither booked nor held by an unexpired hold.
  6. Shows are independent. Seat A1 in one show has nothing to do with A1 in another.
  7. Config validation. Solution.create throws IllegalArgumentException for any of these: no shows, duplicate show ids, a show with no seats, duplicate seats within a show, or a non-positive TTL.

Non-functional requirements

What you get

The judge scores correctness (hidden tests, including multi-threaded ones) and design quality. Each counts for 50%.

com/lld/booking/Solution.java
com.lld.booking
Main.java
Solution.java
com.lld.booking.api
๐Ÿ”’ BookingConfig.java
๐Ÿ”’ BookingException.java
๐Ÿ”’ BookingSystem.java
๐Ÿ”’ HoldExpiredException.java
๐Ÿ”’ InvalidStateException.java
๐Ÿ”’ NotFoundException.java
๐Ÿ”’ SeatUnavailableException.java
๐Ÿ”’ Show.java
Loading...