Uploaded October 2026 | Updated November 2026, 4 days ago
System Design Interview, Day 0001. The question: AC Tatkal opens at 10 in the morning, thousands of people are booking at once, only one berth is left in the Rajdhani 2AC, berth number 20, and two people tap Book Now in the same second. Who gets the seat? Most candidates say "put a database lock on the berth until the payment is done". Sounds right, but in the Tatkal rush that is exactly what jams the database.
- The trap: a DB lock held until payment keeps the lock and a database connection busy for minutes; thousands of such locks fill the connection pool
- The real problem is a race condition: both requests ask "free?", both hear yes, both book. One berth, two tickets
- Fix 1: make check and book one step. One atomic update sets berth 20 to HELD only if it is still FREE. The first request gets 1 row, the second gets 0 rows, is told at once that the seat is gone and is offered the waiting list. This is optimistic locking
- Fix 2: a hold is a status plus a timer, not a DB lock. Payment done: BOOKED. Timer over: FREE again for the next user
- Fix 3: a waiting room queue in front of the database lets users in, in order, at a limited speed
- Fix 4: split reads and writes. Availability comes from a cache or read replica, only real bookings reach the main database. A slightly stale count is fine, because the atomic update decides
- Twist: money debited, screen shows an error, user taps Pay again. An idempotency key per booking attempt means the server returns the first ticket instead of making a second one
One-line answer: the database decides the berth in one atomic step, the hold has a timer, a queue sits in front of the rush, availability comes from the cache, and every retry carries an idempotency key.
In the next System Design Interview episode: it's the IPL final, and tens of millions of people are watching live at the same time. Why doesn't JioHotstar go down? Tell me in the comments how your last Tatkal booking went, and follow for the next episode.
kgptalkie.com
#shorts #SystemDesign #SystemDesignInterview #IRCTC #Tatkal #RaceCondition #OptimisticLocking #Database #Backend #InterviewPrep #SoftwareEngineering #KGPTalkie
System Design Interview, Day 0001. The question: AC Tatkal opens at 10 in the morning, thousands of people are booking at once, only one berth is left in the Rajdhani 2AC, berth number 20, and two people tap Book Now in the same second. Who gets the seat? Most candidates say "put a database lock on the berth until the payment is done". Sounds right, but in the Tatkal rush that is exactly what jams the database.
- The trap: a DB lock held until payment keeps the lock and a database connection busy for minutes; thousands of such locks fill the connection pool
- The real problem is a race condition: both requests ask "free?", both hear yes, both book. One berth, two tickets
- Fix 1: make check and book one step. One atomic update sets berth 20 to HELD only if it is still FREE. The first request gets 1 row, the second gets 0 rows, is told at once that the seat is gone and is offered the waiting list. This is optimistic locking
- Fix 2: a hold is a status plus a timer, not a DB lock. Payment done: BOOKED. Timer over: FREE again for the next user
- Fix 3: a waiting room queue in front of the database lets users in, in order, at a limited speed
- Fix 4: split reads and writes. Availability comes from a cache or read replica, only real bookings reach the main database. A slightly stale count is fine, because the atomic update decides
- Twist: money debited, screen shows an error, user taps Pay again. An idempotency key per booking attempt means the server returns the first ticket instead of making a second one
One-line answer: the database decides the berth in one atomic step, the hold has a timer, a queue sits in front of the rush, availability comes from the cache, and every retry carries an idempotency key.
In the next System Design Interview episode: it's the IPL final, and tens of millions of people are watching live at the same time. Why doesn't JioHotstar go down? Tell me in the comments how your last Tatkal booking went, and follow for the next episode.
kgptalkie.com
#shorts #SystemDesign #SystemDesignInterview #IRCTC #Tatkal #RaceCondition #OptimisticLocking #Database #Backend #InterviewPrep #SoftwareEngineering #KGPTalkie










