In the diagram, one process removes node i and another removes node i+1. Each rewires the arrows correctly on its own, but because both read the old arrows together, one removal overwrites the other. No line of code is wrong; only the timing is.
Take the simplest booking code: read the seat, check it is free, mark it booked. With one user it works perfectly. Now run Rohit's and Sneha's requests on two server threads, with one berth left:
Thread A (Rohit) reads berth 23: free.
Thread B (Sneha) reads berth 23: free.
Thread A checks "is it free?" and gets yes.
Thread B checks too and also gets yes, because A has not written anything yet.
Thread A writes "booked by Rohit".
Thread B writes "booked by Sneha", overwriting Rohit.
Both see success, and two people will board for one berth. Swap steps 2 and 5 and nothing goes wrong, which is why this bug can pass a thousand tests and fail only under heavy load.
Check-Then-Act: The Gap That Causes It
This pattern is called check-then-act, or TOCTOU (time of check to time of use). The danger lives in the gap between checking a fact and acting on it, because another thread can change the fact in those few microseconds. Any code that reads a value, decides, and then writes has this gap unless something closes it.
Lost Updates: When Counters Go Wrong
Counters suffer the same way. If "seats left = 40" and two bookings both read 40, subtract one and write 39, two seats are sold but the counter shows only one gone.
Tatkal is the worst case: AC booking opens at 10 AM and non-AC at 11 AM, one day before the journey, so lakhs of people hit the same few berths in the same second.
In a Railways analysis of 24 May to 2 June 2025, about 5,615 of an average 1,08,000 AC Tatkal tickets went in the first minute, and 62.5% within ten minutes. The old reservation system handled about 32,000 bookings per minute; the revamped IRCTC platform, launched on 15 July 2026 and rolling out in phases, targets more than 1.5 lakh.
My take: a faster system does not remove race conditions. It makes clashes more likely, because more requests land in the same millisecond. Speed and correctness are separate problems.
IRCTC does not publish its internal design, so we cannot say which exact method it uses. But every serious booking system closes the gap with one or more of these four tools.
Atomic Conditional Updates
The neatest fix merges check and act into one indivisible database step:
UPDATE berths SET status = 'BOOKED', pnr = 'P123'
WHERE berth_id = 23 AND status = 'FREE';
Only one such statement can change the row. Rohit's update finds the berth free and changes one row. Sneha's finds no free berth and changes zero rows, so her app shows "not available" instead of a fake success.
Locks and SELECT ... FOR UPDATE
A lock, or mutex (short for mutual exclusion), is a token only one thread can hold. Inside a database transaction, SELECT ... FOR UPDATE reads a row and locks it until the transaction ends. Sneha's thread simply waits at step 2 until Rohit's booking commits, then sees the berth taken. This is pessimistic locking, because it assumes a clash will happen.
Optimistic Locking With Version Numbers
The opposite approach assumes clashes are rare. Every row carries a version number. Both threads read berth 23 at version 7. Rohit saves "only if the version is still 7", and it becomes 8. Sneha's identical save fails, and her app retries with fresh data.
Queues: One Line, One Clerk
Requests for the same train join one line, and a single worker handles them in order, like one clerk at a PRS counter. No parallel access means no race.
Each method trades something away under rush:
Method | How it stops the race | Weak spot |
|---|
Atomic update | Check and write in one step | Fits only simple conditions |
Pessimistic lock | Others wait for the lock | Waiting threads pile up at peak |
|
For a Tatkal-style rush, optimistic locking is the worst choice, because nearly every request clashes.
Locks fix race conditions but create a new risk. A family booking needs berths 23 and 24. Thread P1 locks 23 and waits for 24, while thread P2 locked 24 a moment earlier and now waits for 23.
Neither can move. Students often confuse this with a race condition, but a race gives a wrong answer while a deadlock gives no answer at all. The standard fix is to take locks in a fixed order, say lowest berth number first, so a circular wait can never form; databases also detect deadlocks and cancel one transaction.
Can two people get the same Tatkal berth?
A correctly built system should never allow it, because the final write is protected by a lock, an atomic update or a database constraint. Seeing a berth as available does not make it yours; only a confirmed PNR does.
Why was my money deducted but no Tatkal ticket booked?
Usually because payment and seat booking run in two separate systems: the bank debited you, but the seat was gone or the booking timed out, so the amount is refunded. Payment systems also tag each attempt with a unique ID, so double-clicking "Pay" does not charge you twice.
What is the difference between a race condition and a data race?
A data race is a low-level case where two threads access the same memory location at once and at least one writes without synchronisation. A race condition is the wider timing problem, and it can occur even when every memory access is safe.
What is the difference between a race condition and a deadlock?
In a race condition, threads are under-coordinated and produce a wrong result. In a deadlock, they are stuck waiting for each other, so nothing finishes.
Why is a race condition so hard to debug?
It appears only when operations overlap in an unlucky order, perhaps once in thousands of runs. It often vanishes under a debugger, because the debugger changes the timing.
Race conditions are not just a ticketing issue; they contributed to the Therac-25 radiation overdoses and the alarm failure behind the 2003 North American blackout. Next time the Tatkal berth count drops in seconds, picture thousands of requests reaching for one row and a small lock letting only one through. For students, the lesson is one question: whenever you write "read, check, then write", ask what happens if another thread runs in between. Share this with a friend who books Tatkal every month, and find more simple explainers in our Education section.