IRCTC Tatkal System Design | Optimistic Locking, Queue, Idempotency Key @KGPTalkie
IRCTC Tatkal System Design | Optimistic Locking, Queue, Idempotency Key  @KGPTalkie
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
IRCTC Tatkal System Design | Optimistic Locking, Queue, Idempotency KeyOpen WebUI Install: Your Own ChatGPT with OllamaPandas Crash Course for Machine Learning | DataFrames, GroupBy, and MorePrompt Injection Firewall: Fine-Tune Falcon-H1 90M on MacBook with MLX๐Ÿ”ด LIVE Claude AI + Blender MCP LIVE โ€“ Automate 3D Design with AIClaude Is Helping Build the Next ClaudeQwen 3.8 27B on MacBook Pro M5 Max vs RTX 5090: 31 vs 134 Tokens/sConnect Hermes Agent to Telegram: Control Your AI Agent From Your Phone (2026)How Much RAM Do You Need to Run an AI Model on Your Own Computer? #shortsQwen 3.8 27B vs Claude Opus on a MacBook: 4 Real TestsLangChain Tutorial for Beginners: Short Term and Long Term MemoryStreamlit Tutorial 4 - Working with Status and Progress Indicators
Laxmi Kant | KGP Talkie |

IRCTC Tatkal System Design | Optimistic Locking, Queue, Idempotency Key

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER