Entities & Relations

The interviewer just said…

“Walk me through your domain model.”

This is the whiteboard moment. Draw nouns and one state machine. Resist adding UserProfile, Review, or PaymentGatewayConfig.


What you should do next

Draw six entities and how they connect. Narrate as you go: “A theater belongs to a city and has screens. A show is a movie playing on a screen at a time. Seat availability is per show, not per screen template.”


Entity whiteboard

┌─────────┐     ┌──────────┐     ┌────────┐
│  Movie  │     │  Theater │────▶│ Screen │
│ id,name │     │ id,city  │     │ seats[]│
└────┬────┘     └────┬─────┘     └───┬────┘
     │               │               │
     └───────┬───────┴───────────────┘

         ┌────────┐       ┌───────────┐
         │  Show  │──────▶│ ShowSeat  │
         │ time   │  1:N  │ status    │
         └────────┘       └───────────┘


         ┌────────┐
         │ Ticket │
         └────────┘

Field cheat sheet (matches hub/scripts/movie-ticket-sourced/)

Entity Key fields
Movie id, name
Theater id, name, city, screens[], shows[]
Screen id, theater, seats[]layout template only
Show id, theater, screen, movie, date, time, seats[]
ShowSeat showId, SeatId, status, reserveTimelive inventory
Ticket id, userId, showId, seats[], paymentId
@Builder @Data
public class ShowSeat {
    String showId;
    String SeatId;
    SeatStatus status;
    LocalDateTime reserveTime;
}

ShowSeat is the object interviewers care about — one row per (showId, seatId) with mutable status.


Seat status state machine

    reserveSeat()          bookSeat()
AVAILABLE ──────────▶ RESERVE ──────────▶ BOOKED
    ▲                    │
    │   releaseSeat()    │  (cancel / payment fail / timeout)
    └────────────────────┘

Enum in hub/scripts/movie-ticket-sourced/:

public enum SeatStatus {
    AVAILABLE, BOOKED, RESERVE
}
  • AVAILABLE — anyone can select it
  • RESERVE — soft hold during payment; other users must not get it
  • BOOKED — confirmed; only cancel releases it

Why ShowSeat is separate from Screen seats

Common confusion: “Screen already has List<String> seats — why duplicate?”

Screen.seats ShowSeat
Static layout Per-show inventory
Same for every show on that screen Different status per show
Created when screen is built Row per show × seat at show creation

Tonight’s 7pm and 10pm shows on the same screen share layout but not availability. User A can book A1 for 7pm while A1 is still available at 10pm — two different ShowSeat rows (showId=sh1 vs showId=sh2).