The whole course ▾

System Design · Mock interview 14 of 20

Design a train booking rush

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design a train booking rush, like India's Tatkal.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

The video for this mock interview is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Pick a seat? -> No: pick a class
->
Scale? -> 1M people, 5,000 trains
->
Sold out? -> Join a waitlist
->
Time to pay? -> A few minutes
Functional requirements
Search trains and seats left
Book a class for 1 to 4 people
Join a waitlist when full
Pay, and get berths on a ticket
Non-functional requirements
->
Never sell more seats than exist
->
Fair: in the order people arrived
->
Survive the 10:00 spike
->
Payment failures handled cleanly
Out of scope
Route planning and timetables
Food and extras
Cancellation fees
interviewer
Hi. Let's start.
candidate
Sure. I'll draw as I go.
interviewer
Design a booking system for a train ticket rush, like India's Tatkal. Seats on every train are released the day before, at ten in the morning, and on popular trains they're gone in a minute or two.
candidate
Okay. I've seen that rush myself. Before I draw anything, let me ask a few questions.
interviewer
Go ahead.
candidate
Do travellers pick a seat on a map?
interviewer
No. They choose a train, a date, a class and how many passengers, and berths are assigned.
candidate
What scale?
interviewer
About a million people at ten o'clock, across five thousand trains.
candidate
What happens when a class is sold out?
interviewer
They can join a waitlist, and move up when others cancel.
candidate
And how long do they get to pay?
interviewer
A few minutes.
candidate
Okay. No seat maps changes a lot.
candidate
So, what it does. Search trains between two stations, with how many seats are left in each class. Book a class for one to four passengers. Join a waitlist when it's full, with a clear position. And pay, then get a ticket, with berths assigned.
candidate
And how well. Never sell more seats than exist. Fair: served in the order people arrived, not by who has the fastest connection. Survive the ten o'clock spike, every day. And handle payment failures cleanly, because at ten o'clock the payment providers are overloaded too.
interviewer
Good point.
candidate
I'll leave out route planning and timetables, food and extras, and cancellation fees. Does that match what you had in mind?
interviewer
Yes. And assume the busiest train has a hundred thousand people chasing a few hundred seats.

Estimation

Estimation
Back of the envelope
1M people × ~10 requests in the first minute
~ 170,000 requests a second at 10:00
5,000 trains × ~10 classes = 50,000 counters
Hottest train: 100,000 people, ~500 seats
WHAT THE NUMBERS DECIDE
Theinventoryistiny
counters,andafeware
extremelyhot:theproblem
iscontention,notsize.
candidate
Let me size it. I think the data is tiny, and the fight is huge.
interviewer
What load are we dealing with?
candidate
The requests, then the inventory, then the hottest train.
candidate
A million people, each making about ten requests in the first minute, searching, refreshing and booking, is ten million requests: around a hundred and seventy thousand a second. The inventory is tiny: five thousand trains, about ten classes and quotas each, so fifty thousand counters of seats left. And the hottest train has a hundred thousand people chasing about five hundred seats in one class.
candidate
So storage is trivial, and the total traffic is manageable with a waiting room. The real problem is contention: a hundred thousand people trying to decrease the same few counters at the same moment.
interviewer
That's where this interview is decided.

API and data

API and data
Inventory
train, date, class ->
seats left
Bookings
passengers, state,
waitlist no.
Berths
coach, berth ->
booking
takes seats
assigned
Endpoints
1
GET /trains?from&to&date ->
seats left
2
POST /bookings -> booking ID,
queued
3
GET /bookings/{id} -> held,
waitlisted…
4
POST /bookings/{id}/pay + key
candidate
Next, the API. Bookings can't be answered instantly at ten o'clock, so it's built for waiting.
interviewer
What does the API look like?
candidate
Search, book, pay, and find out what happened.
candidate
GET trains between two stations on a date, with seats left per class, from a cache a second or two old. POST a booking, with the train, class and passengers, which returns a booking ID straight away, in state queued. GET the booking to see what happened: held for payment, waitlisted with a number, or rejected. And POST to pay, with an idempotency key.
interviewer
Why not answer the booking straight away?
candidate
At ten o'clock, the honest answer is: you're in line.
candidate
Three tables. Inventory: for each train, date, class and quota, a count of seats left, and the next waitlist number. Bookings: the passengers, the state, and a waitlist number if they have one. And berths: each coach and berth, and which booking it belongs to. The key choice: booking takes from a count, and berths are assigned afterwards.
interviewer
Why does that matter?
candidate
Nobody fights over berth thirty-two. They fight over a number.

High-level design

High-level design
Travellers
Waiting
room
admits a
steady
flow
Booking
service
Booking
requests
Kafka,
keyed
by
train
10:00:00
admitted
1
book 2 in
3AC
2
Train
processor
one
writer
per train
Inventory
DB
Payment
provider
in order
3
seats − 2,
hold
4
pay within
minutes
5
A booking's states
1
Queued: waiting its turn
2
Held: seats reserved, pay now
3
Confirmed, with berths
4
Or waitlisted, or expired
TWO QUESTIONS
Whyasinglewriterper
train,notlocks?And
howdowaitlistsand
paymentsholdup?
interviewer
Okay. Show me the design.
interviewer
Walk me through one booking, at ten o'clock exactly.
candidate
I'll start where the crowd starts: the front door.
candidate
Travellers arrive at a waiting room, which admits a steady flow to the booking service, at the rate the system can handle. The booking service checks the request, saves it as queued, and publishes it to a topic of booking requests in Kafka, partitioned by train. So every request for the same train lands in the same partition, in the order it arrived.
interviewer
Why Kafka, and not a queue table in the database?
candidate
Kafka keeps the order within a partition, and takes a hundred and seventy thousand messages a second easily.
candidate
Each partition is read by one train processor: the only writer for those trains' inventory. It takes requests one at a time, in order. Seats left? Take two, record a hold, and mark the booking held. None left? Give the next waitlist number. It writes the result to the inventory DB, and the traveller is told within seconds. Then they pay through the payment provider before the hold expires.
candidate
So a booking moves through states, only forwards. Queued, waiting its turn. Held: seats reserved, with a few minutes to pay. Confirmed, once payment succeeds, with berths assigned. Or waitlisted, with a number. Or expired, if the traveller didn't pay in time, and the seats go back to the next person in line.
interviewer
Why a single writer, and not many servers updating the counter with locks?
candidate
That's the first thing I'd like to defend. The second is how waitlists and payments behave when everything is overloaded.
interviewer
Let's start with the writer.

Deep dive: the hottest train

Deep dive: the hottest train
Every server updates the row
All requests fight over one row
Lock waits and timeouts pile up
Order depends on luck
One writer per train, in order
Requests queue in a partition
One process, no lock fights
Strictly first come, first served
THE CHOICE
Partitionbytrain;one
processorownseach
train'sinventory,and
servesrequestsinorder.
High-level design
Travellers
Waiting
room
admits a
steady
flow
Booking
service
Booking
requests
Kafka,
keyed
by
train
10:00:00
admitted
1
book 2 in
3AC
2
Train
processor
one
writer
per train
Inventory
DB
Payment
provider
in order
3
seats − 2,
hold
4
pay within
minutes
5
thousands of bookings/s per
train
the line, in arrival order
A booking's states
1
Queued: waiting its turn
2
Held: seats reserved, pay now
3
Confirmed, with berths
4
Or waitlisted, or expired
TWO QUESTIONS
Whyasinglewriterper
train,notlocks?And
howdowaitlistsand
paymentsholdup?
interviewer
The hottest train, then.
interviewer
A hundred thousand requests hit one train's seat counter in a minute. For concert tickets, you'd use a conditional write. Why not here?
candidate
Let me compare the two honestly.
candidate
With a conditional write, every booking server updates the same counter row at once. Correct, but with a hundred thousand attempts in a minute on one row, the database spends its time queueing locks, requests time out, and who wins depends on luck and network speed. With one writer per train, requests wait in their partition in arrival order, and one process works through them, in memory, with no fights over locks. Simpler, faster here, and fair by construction.
candidate
So, one writer per train. The inventory makes it possible: it's tiny, and it splits naturally by train. Many trains share a partition, and many partitions run in parallel, so all five thousand trains are handled at once, but each train has exactly one writer.
interviewer
And for seats on a map?
candidate
Then I'd go back to conditional writes. A counter per class is what makes this cleaner.
candidate
Kafka is the line, keeping each train's requests in arrival order. The train processor keeps that train's counters in memory, so each decision takes microseconds, and writes the results to the database in small batches. Five hundred seats are allocated in well under a second. The rest of the minute is spent telling everyone else, politely, that they're waitlisted.
interviewer
Doesn't batching risk losing a decision in a crash?
candidate
The decisions can be rebuilt from Kafka's offsets, so nothing already decided is lost.
interviewer
The processor for the busiest train crashes in the middle of the rush. Now what?
candidate
Another processor takes over its partition, rebuilds the counters from the inventory DB, and resumes from the last offset it saved. Requests it reads again are recognised by booking ID, and skipped. A pause of a few seconds, and no seat sold twice.
interviewer
Is it really fair, when people reach different servers a few milliseconds apart?
candidate
Much fairer than a lock race. Requests are ordered by when they entered the line. And for everyone already waiting before ten, the waiting room can shuffle their places, so arriving at nine fifty-nine, or refreshing faster, gives no advantage.
interviewer
Good.

Deep dive: waitlists and payments

Deep dive: waitlists and payments
The waitlist
1
Sold out: the next waitlist number
2
A cancelled or expired hold frees seats
3
The processor confirms the first in line
4
Before departure: confirmed or refunded
PAYMENTS UNDER LOAD
Holdsexpire;payments
carryidempotencykeys;a
latesuccessafterexpiry
isrefundedautomatically.
interviewer
Now, the messy part.
interviewer
How do the waitlist and payments work, when the payment provider is struggling just like everyone else at ten o'clock?
candidate
The waitlist first.
candidate
When a class is sold out, the processor hands out the next waitlist number, in order. Whenever a hold expires, or a ticket is cancelled, that frees seats, and the same processor, still the only writer for that train, confirms the first people on the waitlist, in order. And a few hours before departure, the list is fixed: anyone still waitlisted is refunded automatically.
candidate
Then payments. Each hold has a time limit, so slow or abandoned payments give seats back to the line. Every payment carries an idempotency key, so retries can't charge twice. Calls to the provider have timeouts and a circuit breaker.
interviewer
And a payment that succeeds just after its hold expired?
candidate
The confirm step fails its check, and the money is refunded automatically.
interviewer
Agents with bots grab hundreds of tickets at ten and resell them. How do you stop it?
candidate
Verified accounts only, with a check like a CAPTCHA to enter the waiting room. A limit on how many rush bookings one account can make in a month, and on passengers per booking. Rate limits per account and per device. And a check afterwards for accounts that book far more than any traveller would.
interviewer
The search page said twelve seats left, but the booking came back waitlisted. Is that a bug?
candidate
No. Search comes from a cache a second or two old, because a hundred and seventy thousand requests a second can't all read the live counter. The processor is the only source of truth. The app should say: seats are selling fast, and the number may already be lower.
interviewer
Fair.

Wrap-up

Wrap-up
Next steps
1
Smarter berth assignment, families together
2
Predict waitlist chances from history
3
Watch queue length and payment success
4
Practise the 10:00 load every week
INTERVIEWER'S FEEDBACK
Strong:sawthehotcounters,a
singlewriterpertrain,awaitingroom,
holdsandwaitlists.Nexttime:bring
berthsinearlier.Verdict:stronghire.
interviewer
We're nearly at time.
interviewer
What would you improve with more time?
candidate
A few things.
candidate
First, smarter berth assignment, keeping families in the same coach. Second, predict each waitlist number's chance of confirming, from past cancellations, so travellers can decide whether to wait. Third, I'd watch the waiting room's length, each processor's lag, and payment success, every morning at ten. And fourth, practise the ten o'clock load with test traffic, because a rush that happens every day deserves a rehearsal.
interviewer
Okay, let's stop there. Very good. You noticed the inventory is a handful of hot counters, and that contention, not size, is the problem. One writer per train, fed by an ordered queue, makes allocation fast, correct and fair, and the waiting room turns the stampede into a line. One gap: berth assignment came up only at the end, and families care about it. I'd say a strong hire.
candidate
Thank you. I'll bring berths in earlier.
Interviewer's feedback

Strong: saw the hot counters, a single writer per train, a waiting room, holds and waitlists. Next time: bring berths in earlier. Verdict: strong hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.