How bookmyshow or any ticket booking site make sure that no two person book the same seat assuming they both clicked at the same time?


#1

How bookmyshow or any ticket booking site make sure that no two person book the same seat assuming they both clicked at the same time?


#2

The concept under this type of process is
When someone selects that registration booking, add a record to the table; this record prevents anyone else from selecting that booking. (INSERT INTO bookings(some,fields,bookedtime,status) VALUES(‘quack’,‘moo’,NOW(),0) )

Whenever someone indicates they’re in the process of booking that slot (IE: Every time they page reload in the same session, moving through the checkout process), update the table.
(UPDATE bookings SET bookedtime = NOW() WHERE somefield = ‘someidentifier’

Every X minutes, cron the database with “DELETE FROM bookings WHERE status = 0 AND bookedtime < CURRENT_TIME - INTERVAL 15 MINUTE”.