This repository was archived by the owner on Oct 25, 2026. It is now read-only.
Repository navigation
Booking and Locking
Syed Ahmer Shah edited this page Oct 25, 2026
·
2 revisions
sequenceDiagram
autonumber
actor C as Customer
participant App as Laravel
participant DB as MySQL
participant Q as Queue
C->>App: Pick seats (POST cart)
App->>DB: BEGIN · lock user → show → seats → cart (FOR UPDATE)
App->>DB: check v_seat_availability, insert cart_items
DB-->>App: COMMIT (seats held 10 min)
C->>App: Confirm checkout (idempotency key)
App->>DB: BEGIN · same lock order · re-check hold, prices, coupon, gift card, points
App->>DB: insert booking + booking_seats (seat_lock = 1), delete cart
DB-->>App: COMMIT
App->>Q: receipt email, loyalty, notifications
App-->>C: QR e-ticket
- Up to 4 seats per booking, one show per booking. Adult and child tickets can be mixed, with at least one adult.
- Seats are held for 10 minutes with a countdown. Expired holds go back on sale and the show's waitlist is told.
- Unpaid bookings can be cancelled online until 2 hours before the show; seats, coupon use, gift card balance and points are returned.
stateDiagram-v2
[*] --> confirmed: checkout
confirmed --> completed: show finished
confirmed --> no_show: not admitted
confirmed --> cancelled: customer or admin
completed --> [*]
no_show --> [*]
cancelled --> [*]
Allowed moves live in Booking::STATUS_TRANSITIONS. Booking::claimStatus() runs UPDATE ... WHERE id = ? AND booking_status = <expected> and throws StaleStatusException if nothing matched, so a booking can't be refunded twice.
| Level | Mechanism |
|---|---|
| Row locks |
SELECT ... FOR UPDATE in a transaction, always in the order user → show → seats → cart, so two requests can't deadlock each other |
| Status lock | Compare-and-set on booking_status (above) |
| Unique constraint |
booking_seats (show_id, seat_id, seat_lock): seat_lock is 1 while sold and NULL once released, so MySQL refuses a second live ticket |
| Idempotency keys | Checkout carries a client key (bookings.idempotency_key, unique); a double-click returns the booking already made |
| Guarded updates | Conditional UPDATEs for counters and one-time notifications |
| Atomic cache locks |
ProcessShowWaitlist is ShouldBeUnique and WithoutOverlapping; scheduled tasks use withoutOverlapping()
|
| Deadlock retry | Booking transactions use DB::transaction(..., 3)
|
The full story, including the IDOR and key-handling fixes, is in One seat, two buyers: race conditions, IDOR and keys in BookMyMovie.
BookMyMovie · MIT licence · by Syed Ahmer Shah · Project page
Run it
How it works
Operate it
Read more