Library
37 min read

Design IRCTC tatkal booking

At 10am the tatkal window opens. (Tatkal is the quota of train seats kept for people who need to travel at short notice.) For the next ten minutes a system that spends most of its day fairly idle takes a couple of hundred times its normal traffic. Almost all of it wants the same few hundred seats, on the same few trains.

Watch one booking go all the way through.

ClientsWaiting roomFair queueAPI tierAvailability cacheBooking serviceInventoryHold sweeperPayment gatewayTicketing

Arrive. At 10am everyone lands on the waiting room, not on the booking service. It does almost no work per request, so it can take the whole burst.

This is not the URL shortener's problem wearing a hat. There, every request could be served, and the work was spreading load. Here most requests must fail, because there are far more people than seats. The design question is how to fail them quickly, fairly and without taking the system down on the way.

A few words come up all through this page:

  • A hold is a seat taken out of inventory for a few minutes while you pay. Nobody else can buy it, and if you never pay, it goes back.
  • The waiting room is a page that gives you a place in line before you are allowed to book, like the token machine at a bank counter.
  • Atomic means "all at once or not at all". An atomic update checks and changes a value in one step, so nothing can sneak in between the check and the change.
  • Inventory is the count of seats still for sale, one number per train, date and class.

Step 1: Understand the problem#

The interesting requirements here are about fairness and about failure, not about raw speed. Ask what a rejected user is owed, because that answer shapes the front of the system.

You askThey sayWhat it settles
How much traffic, over what window?A couple of hundred times normal, for about ten minutes, at a time everybody knows in advance.You can prescale, which means adding servers before the rush instead of during it. The spike is scheduled, so capacity is a calendar problem, and the design only has to survive a known ten minutes rather than an unknown one.
How many of these requests can succeed?Almost none. A few hundred seats on a popular train, a few hundred thousand people.The whole shape. This is a rejection system, so the goal is to fail people cheaply and early rather than to serve everybody.
Can the same seat ever be sold twice?Never.A single place per train where seats are claimed one after another. "Copies catch up later" is not an answer for seat inventory, and pretending otherwise is the fastest way to fail this question.
Does it have to be fair, or just fast?Fair. First come first served, visibly.A queue with a position you can show people, rather than a retry storm where the fastest network wins. Fairness is a product requirement, not a nicety.
What happens between choosing a seat and paying for it?The seat is held for a few minutes.A hold with a hard expiry, and a sweeper that releases abandoned holds. Every unpaid hold is a seat nobody else can buy.
Is stale availability acceptable?Yes, as long as booking is exact.The "seats left" number can be cached and a little out of date, which removes the vast majority of reads from the database. Only the commit has to be true.

What you are building#

Functional requirements
What the system does.
  • Search trains and see availability. Read heavy, cacheable, and the first thing to fall over.
  • Hold specific seats for a few minutes while the user pays. The hold is the hard part, not the booking.
  • Confirm on payment, release on timeout. Money and inventory live in two systems, which is the payment rail problem again.
  • Never sell the same seat twice. Non negotiable. Everything else can degrade.
Non-functional requirements
How well it has to do it. The numbers you commit to.
  • A ten minute window carrying about 200 times the normal rate.
  • Correctness over availability on inventory. A wrong booking is worse than a failed one.
  • Tell a user they failed within a couple of seconds. A spinner that lasts 90 seconds is worse than a fast rejection.
  • Fairness: arriving first should count for something.
Out of scope
What you cut, and say so out loud.
  • Cancellations, refunds and the waiting list promotion rules. Genuinely complex, and a separate design question.
  • Fare and quota calculation. Deep domain logic that changes nothing structural here.
  • Fraud and bot detection. Enormous in practice on this exact system, and worth naming as a real constraint.
  • Seat allocation preferences. Assume seats are interchangeable within a class.

"Correctness over availability" is the same choice the CAP theorem describes: when a network fault splits the system, each part can either keep answering or stay correct, not both. Inventory stays correct, and refuses to answer if it has to.

Back of the envelope#

Before the sliders, a small version you can do in your head. One train has 400 seats and 200,000 people want them. That is 500 people per seat. If every one of them gets an answer, 499 out of every 500 answers are "no". (The back of the envelope chapter covers the method.)

The napkin below counts the whole rush across all trains together, so its default is more seats and more people than one train.

Demand against supply
400 thousand
5000
6
People competing400,000
People per seat400,000 / 5,000 = 80 to 1
Requests, with retries400,000 x 6 = 2,400,000
Peak rate over two minutes20,000 per second
Requests that must fail98.75%
80 to 1
people per seat, and this ratio is the design

Almost every request is going to fail. That reframes the whole problem: the system is not a booking system during this window, it is a rejection system that occasionally books. Rejecting cheaply, early, and before anything touches the inventory database is where the design effort goes.

The retry multiplier is not a constant

Drag the attempts slider. Retries are the one input the system controls. A fast, clear rejection produces one or two retries. A request that hangs for thirty seconds and then times out produces six, because the user has no idea what happened and taps again. Slow failure manufactures its own load, which is why "fail fast" is a capacity decision here and not a nicety. Retries multiply load shows the same effect inside a backend.