System design round

Design IRCTC Tatkal Booking

Tatkal is a flash crowd on a timetable. Everyone arrives in the same five minutes, mostly for the same few trains, and nobody may get a berth that someone else already has.

Estimate, draw your design, run its traffic through it and see which boxes break. Then answer the follow-up questions. The load test is free and needs no account; an AI review or score uses one of your AI replies.

The brief

It must

  • Search trains, show seats left, book seats for up to four passengers, and pay.
  • Two people can never get the same berth.
  • Stay up and stay fair when the window opens: first come, first served, not fastest bot first.
  • Held seats go back on sale if payment does not finish in time.

The numbers

  • Tatkal for AC classes opens at 10:00 AM. Assume 2 million people try to book in the first five minutes.
  • Each checks seat availability about 10 times.
  • Most want the same 10 popular trains, and about 150,000 Tatkal berths are on offer.
  • The payment gateway takes 3,000 payments a second and about two seconds to answer each.

Before you draw: the numbers

Interviewers expect a quick estimate first, because the numbers decide the design. Write yours, then check.

The load test uses round numbers per box, the kind you would use on a whiteboard, so it shows where a design breaks and roughly by how much, not exact figures. How it works

The follow-up questions

Once your design is up, the interviewer goes deeper. Each question changes one thing and is a level further, Fresher to Senior. An AI interviewer scores your answer; 6 out of 10 or more climbs the rung.

IRCTC Tatkal booking

Not climbed yet

Our design, and why

Try your own first. “Our design” on the board shows it as boxes you can load-test.

Two numbers set the design: about 67,000 availability checks and 6,700 booking attempts a second, and nearly all of the attempts aimed at 10 trains. The first is a caching problem. The second is a contention problem, and caching cannot help it.

  • Availability is read-mostly and may be slightly stale. A CDN caches it for a few seconds, Redis behind the search service catches most of the rest, and the database sees a few thousand reads a second.
  • Seat counts live in Redis. Each booking takes a berth with an atomic decrement in a Lua script that refuses to go below zero. In SQL, every attempt on a popular train would queue for the same row lock: 10 rows at about 200 updates a second each is 2,000 a second, against 6,700, and sharding does not help a single row. Postgres keeps the bookings, and a job reconciles the two.
  • A waiting room in front of booking admits people in arrival order at the pace booking can take, with a signed token so calling the API directly does not skip it. Searching does not wait in it.
  • Pre-scale before 10:00. Autoscaling reacts in minutes; the rush is over in five.

Payments take two seconds each at the gateway. Hold the seat with an expiry while the user pays, treat a timeout as unknown rather than failed, and reconcile with the gateway so nobody pays without a ticket.

What each level is expected to cover

The AI review grades your board against these.

Fresher
  • Trains, an inventory per train, date and class, and bookings with states.
  • Search, availability and booking endpoints.
SDE 1
  • An atomic conditional decrement (or row lock) so the last berth is sold once.
  • Caching availability, since it is read far more than booked.
SDE 2
  • A waiting room or admission control for the 10 AM spike.
  • The hot row on popular trains, and moving the counter to Redis or splitting it.
  • Pre-scaling, CDN for static content, bot and per-account limits.
Senior
  • Seat holds with expiry and a booking state machine.
  • Payment timeouts as unknown, idempotent callbacks, reconciliation and automatic refunds.
  • Keeping Redis and the database of record consistent, and recovering after a Redis restart.

How the load test works

Each round sends a few kinds of traffic from its users, at the rates in the brief. The test follows your arrows: a CDN answers what it can cache, a load balancer spreads requests, a service runs the logic and checks a cache beside it before the database, and a queue takes work off the request so the boxes after it work at their own pace.

Every box takes a rough number of requests a second (one service machine about 5,000, one Redis node about 100,000, one SQL primary about 3,000 writes, one row about 200 updates). A box asked for more turns red and drops the excess, unless a queue in front holds it back, in which case the queue grows and the work waits. Failure scenarios take machines away; a standby copy covers one.

It cannot see correctness: idempotency, consistency, and what users see when something fails. Write those in a box’s note; the AI review reads them.

blur