KatInterview

Limited-Stock Flash Sale Platform with Zero Oversell

System DesignModel answer
HardModel answerSystem Designsystem-designhigh-concurrencyredis

Last updated

Design a platform that sells a fixed number of seats or units to millions of simultaneous buyers, with no oversell, no double charge, and graceful behavior under failure.

Problem

You are designing the backend for a limited-stock sale, such as tickets for a very popular concert. Stock is fixed, for example tens of thousands of seats. When sales open, the platform may receive millions of purchase attempts per second, yet only a small fraction of buyers can succeed. The system must never sell more than exists and never charge anyone twice.

The venue has two kinds of inventory:

  • General admission (GA): buyers pick a quantity, not a specific seat.
  • Reserved seating: buyers pick specific seats, and a request must succeed or fail as a whole.

What to cover

  1. Admission control and fairness. How do you keep the stampede away from the core services? Choose a fairness model (arrival order, lottery, or a mix) and justify it. Explain how rate limiting and backpressure tie the admission rate to backend capacity.
  2. Preventing oversell. Explain how you guarantee zero oversell in both inventory modes. Compare holding stock temporarily with deducting it immediately, and describe expiring holds and how stock is returned after a timeout or cancellation.
  3. Bots and abuse. Describe your defenses and how you enforce per-person purchase limits (for example, a few tickets per account, device, or card).
  4. Idempotency. Make reservation and order creation safe to retry, including duplicate payment-provider callbacks.
  5. Hot-spot avoidance. Show how you avoid one global counter becoming the bottleneck.
  6. APIs. Sketch the main endpoints, idempotency headers, and error codes.
  7. Data model and partitioning. Name the entities and the shard or partition keys, for both the durable store and the fast in-memory allocation path.
  8. Read and write paths. Describe caching, how clients see live availability, and the flow from queue to hold to paid order.
  9. Messaging. Explain how an asynchronous bus is used, which delivery guarantees you rely on, and how consumers stay correct.
  10. Consistency and reconciliation. State where you need strong consistency and where eventual is acceptable, and how the fast allocator and the durable ledger are kept in agreement.
  11. Failure handling. Cover timeouts, retries, circuit breakers, degraded modes, and what happens when the cache, the database, or the payment provider fails.
  12. Capacity, SLOs, and testing. Give concrete numbers and a test plan that demonstrates zero oversell under extreme load.
  13. Monitoring. List the key metrics and alert thresholds.

Treat this as a generic limited-inventory design problem. State your assumptions about scale up front.

Hints

Hint 1

Start by sizing: millions of requests per second but only tens of thousands of possible sales. Most traffic should be absorbed at the edge, so the real question is how to let in only as many people as the allocator can handle.

Hint 2

Correctness should live in one place: a single atomic operation per shard (for example a Redis Lua script) that checks stock, checks the buyer's quota, and records a hold with an expiry. Everything else (queues, caches, UI) can be eventually consistent.

Hint 3

Split the stock across many sub-keys so no single key is hot, and make every step retry-safe by deriving hold IDs from the idempotency key and deduplicating payment callbacks by provider event ID.

Hint 4

Treat Redis as a fast allocator and the database as the ledger of record, then plan the unhappy paths: expired holds, late payments (refund), crashed allocator (rebuild from ledger), and a periodic reconciler that compares both.