System design round

Design a Flash Sale

A flash sale is a million people racing for a thousand units. Showing the page is easy to scale; taking stock is not, because every purchase changes the same number.

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

  • Show the product page to everyone who comes.
  • Never sell more phones than exist.
  • Reserve a phone for a buyer while they pay; unpaid reservations go back on sale.
  • Most people will hear "sold out". Tell them quickly.

The numbers

  • Assume 1,000 phones go on sale at 12:00.
  • A million people press Buy in the first minute, each after loading the page about five times.
  • One database row can take about 200 updates a second: each holds the row lock for about 5 ms.

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.

Flipkart flash sale

Not climbed yet

Our design, and why

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

Page views are a caching problem: the CDN answers 90% and Redis most of the rest. Buy presses are a contention problem: 16,700 a second all change one number, and in SQL that number is one row whose lock lets about 200 updates a second through. No amount of hardware fixes a single row.

  • The stock count lives in Redis. A Lua script checks and decrements in one step, so it never goes below zero, at tens of thousands a second. Postgres only records the thousand winners.
  • Alternatives worth naming: split the stock across 10 rows of 100 (each buyer tries a random one), or pre-issue 1,000 tokens in a Redis list and let buying start with LPOP.
  • Answer "sold out" fast: once the count hits zero, everyone else hears it from the cache in milliseconds.
  • Reserve, then pay: a reservation holds the phone for a few minutes; an expiry worker returns unpaid ones, with a conditional update so a late payment and the expiry cannot both win.

Bots are part of the load: rate limits per user and per IP address, one reservation per account, and a captcha before 12:00 keep the crowd human-sized.

What each level is expected to cover

The AI review grades your board against these.

Fresher
  • Products, stock, orders with states.
  • Reserve and pay endpoints.
SDE 1
  • An atomic conditional decrement so the 1,001st phone is never sold.
  • Reserve, then confirm on payment.
SDE 2
  • The hot row: why one row caps throughput, and Redis, split rows or tokens as fixes.
  • CDN for the page, per-user rate limits, a waiting room, bot checks.
Senior
  • Reservation TTLs, an expiry worker, and the race with late payments.
  • Idempotent payment callbacks and refunds for expired orders.
  • Fairness: returned stock goes to the next in line.

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