The interview problem
Design a sealed-bid service for five identical equipment-reservation slots. Each verified bidder may request one slot. Bids close at a declared deadline. Allocate capacity deterministically, collect payment and offer a released slot to the next eligible bidder without overselling when workers retry or payment responses are lost.
Original system-design practice, not a reported company interview. Rules and quantities are hypothetical product assumptions, not auction-theory or legal advice. Primary technical documentation retrieved September 27, 2026; interview date not applicable.
1. Fix the auction rules before designing storage
Use a first-price sealed auction: the highest five valid bids above a published reserve win, and each winner pays its own bid. One bidder gets at most one slot. Equal amounts are ordered by the accepted revision sequence, then a stable bidder identifier as a defensive final tie-break. State explicitly that this tie policy rewards earlier accepted revisions; it is deterministic, not a fairness theorem.
Allow replacement and withdrawal before closure. A replacement gets a new acceptance sequence; the latest accepted revision determines the bidder's state. If it is a withdrawal, the bidder has no active offer; never resurrect an earlier bid by filtering withdrawal records out before choosing the latest revision. Losing bids remain private. Winners receive a payment deadline, and confirmed nonpayment permits promotion in the frozen ranking at the promoted bidder's own price. These rules are published before bidding, including how outages and unresolved payments affect settlement.
Define capacity conservation: available + held + confirmed = five. An unknown payment still occupies a held slot. A bidder can have at most one active allocation. Changing pricing to a uniform clearing price would require different settlement and promotion rules; do not accidentally combine the two auctions.
2. Use one authoritative order per auction
bidder → authenticated bid API → auction authority
↓
bid revisions + receipts + auction state
↓
close / freeze revision set and rules
↓
deterministic ranking and allocation plan
↓
held slots + durable payment outbox
↓
payment adapter → receipt reconciliation
↓
confirm allocation or promote next bidderPartition auctions across authorities; keep the ordering for one auction within one authoritative database shard or replicated state machine. Read replicas can serve status, but their lag must not determine deadline acceptance or winners. Do not merge independently accepted regional bid histories after announcing a winner.
Persist auction ID, capacity, reserve, currency, rules version, deadline, state and settlement generation. Each bid revision records bidder ID, integer minor-unit amount, request key, payload hash, acceptance sequence and status. Store idempotent receipts separately from mutable current-bid projections. Reusing a request key with a different payload is an error.
For a modest auction, every bid mutation and close operation takes the same auction-row lock. Under that lock, check the state and authoritative current time, then atomically update the revision, sequence and receipt. A committed receipt is returned only after durability succeeds. A retry of a committed request returns its original outcome, even after closure; it is not a new late bid.
3. Explain exactly what “before the deadline” means
In this design, admission means passing the authoritative check while holding the auction lock strictly before the deadline, followed by successful transaction commit. A request arriving at a load balancer before the deadline is insufficient. A transaction admitted just before the deadline may commit just after it; closing waits behind that transaction. This is a deliberate rule, not a guarantee that all bid commits happen before wall-clock closure.
Read current time after acquiring the lock using a clock with the intended semantics, rather than a timestamp captured when a long-waiting transaction began. After the deadline, a delayed close worker does not extend bidding because every new admission checks time itself. A rollback consumes no accepted revision; retry rechecks admission and may be too late.
The service must monitor authority-clock health and define behavior on clock uncertainty or failover. If it cannot establish a trustworthy deadline decision, suspend admissions and follow the published outage policy instead of accepting conflicting regional clocks. Do not claim that ordinary serialization proves a real-world-time guarantee. A log-position cutoff is easier to order but changes what the customer means by a deadline.
The close transaction checks that the authoritative deadline has arrived, then atomically changes OPEN to FROZEN after earlier admitted transactions commit and captures the accepted revision boundary and rules version. Settlement reads only that immutable set. A worker starting later cannot include a bid simply because it finds the bid in a newer table snapshot.
4. Settle ties in a reproducible example
With reserve $70, the frozen valid bids are A:$120(sequence 8), B:$110(12), C:$100(17), D:$100(21), E:$90(24), F:$90(30) and G:$80(35). Ranking is A, B, C, D, E, F, G. A through E initially hold the five slots. The total payable amount is $120+$110+$100+$100+$90=$520 if all five pay.
C precedes D at $100 and E precedes F at $90 because their accepted sequences are earlier. Database row order, worker start time and floating-point comparisons play no role. The reserve and bid amounts share a declared currency and integer precision.
If C's payment is definitively declined and its allocation is released under the rules, F receives the slot at $90. The successful set becomes A, B, D, E, F, totaling $510. B's price remains $110: this is not a second-price or uniform-price auction. If C's result is merely unknown, F is not promoted yet.
Compute the plan from a frozen input digest and record its rules version and generation. If a worker crashes before publication, another worker can reproduce the same plan. Publish the active generation with a conditional state transition and unique allocation constraints. A stale worker cannot replace a committed generation or issue payment intents for an inactive one.
5. Separate payment intent from confirmed allocation
In one transaction, reserve a slot, create an allocation in PAYMENT_PENDING and write a payment-intent outbox entry. A worker sends the intent with a stable allocation-specific idempotency key if supported by the payment provider. Bind amount and currency to that key. A timeout leaves PAYMENT_UNKNOWN; it does not release the slot.
Reconcile by the provider's durable payment reference or idempotency lookup, and verify callback authenticity and event identity. Duplicate callbacks must not confirm or release twice. Apply only valid transitions from the current allocation generation. Out-of-order notifications require reading authoritative payment state when necessary; an old failure event must not reverse a verified success blindly.
Suppose four allocations are confirmed and C's payment request timed out. The state is confirmed=4, held=1, available=0. Promoting F now would risk six successful buyers for five slots if C's charge succeeded. The safe action is reconciliation or documented manual resolution that preserves the capacity hold, not guessing that a timeout means failure.
A payment deadline is not proof that a previously issued charge cannot complete. Before promotion, establish terminal nonpayment or a verified cancellation/void outcome, and prevent further charge attempts for that allocation. If a provider cannot establish finality promptly, keep the slot held and disclose delayed settlement. A refund after an accidental late charge is compensation, not proof that the original no-oversell protocol was correct.
Only after terminal release does a serialized transaction move the next ranked, still-eligible bidder into a hold and enqueue its payment intent. If no eligible bidder remains, capacity stays available under the auction's declared unsold-capacity policy. Repeated promotions advance a durable cursor or equivalent state without skipping a bidder because a worker crashed.
6. Size the deadline burst and settlement work
Suppose 100,000 bidders submit or revise during the final minute. Average arrival is about 1,667 requests/s, but a tenfold one-second burst reaches roughly 16,667/s. A serialized per-auction transaction taking 2 ms has an idealized ceiling of 500/s before other overhead. More API replicas cannot remove that hot-key bottleneck.
Start with load limits and explicit admission semantics for small auctions. For larger ones, use an ordered durable admission log with batched replication and a frozen cutoff. A durable ingress receipt and a final acceptance receipt must be distinguishable. If batches establish ordering, assign deterministic within-batch sequence numbers. Preserve the same closure invariant; do not call a queued request accepted merely because it is in memory.
For 100,000 final bids, a full sort requires on the order of n log₂ n≈1.66 million comparisons. Keeping only the top five reduces initial selection work, but promotion still needs an ordered remainder or a repeatable way to retrieve it from frozen data. At 256 bytes per revision and three revisions per bidder, raw revision payload is 76.8 MB decimal, excluding indexes, replication and audit records.
Partitioning by auction spreads independent traffic. Splitting one auction's bids across shards introduces a distributed close barrier: every shard must seal its accepted prefix before a global plan becomes authoritative. That can improve ingestion but makes deadline recovery and missing-shard behavior harder. Begin with the simplest authority that meets measured load.
7. Preserve secrecy and recover deterministically
Restrict bid-value access to the bidding and settlement path, encrypt stored data and exclude amounts from public telemetry. Bidder-facing APIs return only the caller's receipt and permitted status. Ordinary server-side encryption does not hide bids from every operator; if the product requires stronger secrecy, a separate cryptographic protocol and threat model are needed.
Test a lost acceptance response, a replacement racing close, a worker dying after sending a charge, delayed success after the payment deadline, duplicate promotions and authority failover. Verify both capacity conservation and receipt stability after each recovery. A database transaction protects internal state but cannot atomically commit a remote charge.
Serializable transactions can help enforce database invariants but require whole-transaction retries on serialization failure. External payment calls must remain outside those retried transactions. Explicit per-auction locking is another implementation choice when every relevant mutation obeys the same protocol; isolation labels alone do not establish the application invariant.
Record rejected-late bids separately from accepted bids for support, without silently reopening the auction. If a bug invalidates a frozen result, pause settlement and use a versioned correction process with affected-user communication. Recomputing new winners behind an unchanged result identifier makes audit and payment reconciliation unreliable.
8. Trade-offs and interview follow-ups
Earlier-sequence ties are simple but favor lower latency. A precommitted random tie-break may reduce that advantage but needs verifiable randomness and a specified seed protocol. First-price settlement is operationally straightforward but changes bidder incentives; do not claim truthful bidding. Strong single-authority ordering simplifies correctness while limiting hot-auction throughput.
Follow-ups: How would multi-unit bids change allocation? How would you implement a uniform-price rule without changing prices during promotions accidentally? What if equipment capacity falls after winners pay? How can a bidder verify inclusion without seeing others' bids? What if the payment provider lacks idempotency? Which guarantee is relaxed if the authority is unavailable at closing time?
9. Self-review rubric
- Specify price, reserve, replacement, tie and promotion rules.
- Define deadline admission and distinguish ingress from durable acceptance.
- Freeze a complete input set and produce a deterministic settlement generation.
- Prove capacity conservation through payment uncertainty and retries.
- Use stable payment identities and terminal evidence before releasing a hold.
- Calculate the hot-auction bottleneck and explain the cost of distributed closure.
- Protect sealed bids and retain auditable corrections.
Sources and related practice
PostgreSQL 17: Transaction Isolation, publication date unspecified; retrieved September 27, 2026. Used for isolation and transaction-retry boundaries. Auction rules, payment protocol and examples here are original design choices.
Continue with reservation waitlists, payment ledgers and distributed transactions.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.