Skip to the page

India-scale design · senior

Tatkal booking, flash sale and oversold stock

Burst events need three things: a waiting room to control entry, one atomic place for stock, and a hold with an expiry. Everything else is cached, degraded or switched off.

The notes

What you must know

  • Separate the read path (search and availability, heavily cached, a few seconds stale is fine) from the write path (booking, strongly consistent).
  • Tatkal inventory per (train, date, class, quota) as counters plus berth allocation. Booking is an atomic conditional decrement (available > 0) or a row lock per inventory bucket, partitioned by train and date so contention stays local.
  • Hold, pay, confirm: a short hold with expiry, released by a timer job if payment does not confirm. Confirm is idempotent. A late payment success after expiry is refunded automatically. Never hold a database lock while waiting for the payment gateway.
  • Virtual waiting room at the edge: tokens in arrival order, users let in at the rate the booking core can take, with a visible queue position. Anti-bot: CAPTCHA, login and device limits, rate limits per account. Real rules as of 2025: only Aadhaar-authenticated users can book Tatkal online (from 1 July 2025, with OTP from 15 July).
  • Flash sale: the product page is static on the CDN; stock shows available or selling fast, not an exact count. Reservation in one fast atomic place: a per-SKU counter in Redis or Valkey (DECR or a Lua script, preloaded), or stock split into buckets to spread the hot key. The database stays the source of truth via async idempotent writes. Reserve, pay, confirm with a TTL (say 10 minutes). Expired reservations return stock. Bots: one unit per account, account-age and KYC checks, CAPTCHA, device fingerprinting.
  • Preparation: load tests above 10 times, pre-scaling (autoscaling is too slow for a spike at 12:00:00), cache warm-up, a feature freeze, runbooks and kill switches for non-critical features.
  • Oversold stock: cause is a read-then-write race (stock read from a 30-second cache, order inserted, stock decremented with no condition). Fix with UPDATE ... SET stock = stock - 1 WHERE sku = ? AND stock > 0 and check rows affected, or a Redis Lua reservation. A lock in Java code does not help with 40 servers.
  • For extra orders decide with the business: cancel the latest ones by time with apology, instant refund and a coupon, or fulfil some if stock arrives. Never cancel at random or silently.

The red pen

Common traps: mistake → fix

  • Mistake: Just autoscale

    Fix: too slow for a spike.

  • Mistake: SELECT stock then UPDATE if above zero

    Fix: it oversells.

  • Mistake: One database row as the counter for 50 lakh users

    Fix: a hot row.

  • Mistake: Show exact live availability to everyone

    Fix: it drives load; show coarse status.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design Tatkal ticket booking.
  2. Design a flash sale for a big sale day.
  3. Stock was oversold on sale night. What do you do now and later?
  4. How do you stop bots?
  5. How do you prepare in the last week?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview