How I Fixed a Race Condition in a Live Seat Booking System (And Lost Sleep Over It)
javascript
dev.to
𝗧𝘄𝗼 𝘂𝘀𝗲𝗿𝘀. 𝗢𝗻𝗲 𝘀𝗲𝗮𝘁. 𝗧𝗼𝘁𝗮𝗹 𝗰𝗵𝗮𝗼𝘀. It was a regular Tuesday on a client project — a bus ticket booking platform. Everything looked fine until a support ticket landed: two passengers had been assigned the same seat on the same trip. My first instinct? "That can't happen — I have a check before booking." Famous last words. 𝗪𝗵𝗮𝘁 𝘄𝗮𝘀 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗵𝗮𝗽𝗽𝗲𝗻𝗶𝗻𝗴: User A and User B both queried the seat at nearly the same millisecond. Both saw it as available. Both proceeded to book. The database u