"Design an online auction" looks like a listing site with a Bid button. The first twenty minutes are the easy part: list an item, search for it, show it, take a bid. The difficulty is hiding in the last twenty seconds of a popular auction.
Thousands of people bid at once, each bid is only valid if it beats the current highest, and the order in which bids are accepted decides who wins money and who loses it. Then the clock runs out, and someone's bid arrives a few milliseconds late. The interviewer is testing whether you can give one auction a single, ordered view of its bids, decide fairly at the deadline, and tell a very large audience about price changes without a delivery storm.
This differs from the other marketplace questions. A flash sale decides winners by an atomic counter, and Ticketmaster by unique seats. In an auction, the winning condition changes with every accepted bid, and the end is a moment in time. The consistency vocabulary is in consistency patterns, and safe retries in idempotency.
Clarify the requirements
Functional requirements:
- A seller lists an item with a starting price, a minimum increment and an end time.
- Buyers search for and watch items, and place bids.
- A bid is accepted only if it exceeds the current price by the increment.
- Buyers can set a maximum bid, and the system bids for them in increments (automatic bidding).
- When the auction ends, the highest bidder wins, and both sides are notified.
Out of scope, said aloud: payment and shipping, seller ratings, fraud review, search ranking and categories, buy-it-now listings.
Non-functional requirements: these decide the design.
- Bids are totally ordered per auction. Everyone must agree which bid came first and which is highest. This is strong consistency, scoped to one auction at a time.
- The end is exact and fair. A bid received before the end time counts, and one received after does not, with the same rule for everyone.
- Hot auctions must not block the rest. One famous item cannot slow down the other 20 million.
- Watchers see price changes quickly, but a second of delay on the displayed price is acceptable. The bid decision itself is not allowed to be stale.
- A retried bid is not a second bid.
Estimate the scale
Assume 20 million live auctions, 10 million daily active users, and 2 million bids a day.
Average bids: 2M ÷ 86,400 ≈ 23 per second. That is tiny, and it says the system is not hard on average.
Reads: if each user views 20 pages a day, 10M × 20 = 200M ÷ 86,400 ≈ 2,300 per second. Item pages are cacheable except for the live price.
The hot auction: bids concentrate at the end. Suppose one auction draws 5,000 bidders who place 20,000 bids in its last 10 seconds, which is 2,000 bids per second on one item. One database row updated in a few milliseconds handles roughly 200 to 500 updates a second, so 2,000 a second on one row is more than it can take.
Watchers: if 100,000 people watch that auction and each should see price changes about once a second, pushing is 100,000 messages per second for one item.
Storage: 2M bids × 200 bytes = 400 MB a day, about 730 GB over five years.
"The average is 23 bids a second, so the system is mostly idle. The whole problem is the last seconds of one hot auction: 2,000 ordered decisions a second on one item, and 100,000 watchers to tell. So I need per-auction serialization that is cheap for rejected bids, and a way to coalesce updates to watchers."
Adjust the assumptions in the capacity estimator.
API and data model
POST /v1/auctions/{id}/bids { bidId, maxAmount } (bidId is the idempotency key)
-> { status: leading|outbid|rejected, currentPrice }
GET /v1/auctions/{id} -> item, currentPrice, leader (masked), endsAt, bidCount
GET /v1/auctions/{id}/stream -> server-sent price and end-time updates
POST /v1/auctions { item, startPrice, increment, endsAt }auctions (id PK, seller_id, current_price, leader_id, leader_max, increment,
ends_at, version, status: open|closed)
bids (auction_id PK, seq SK, bid_id UNIQUE, bidder_id, amount, accepted, received_at)The non-obvious choices are the bid_id supplied by the client, which makes a retry return the earlier result, and the monotonically increasing seq per auction, which gives bids an order that everyone can point to.
High-level design
The slice worth running is bidding: a load balancer, a stateless bid service, a fast store for the current price, and the database holding every bid.
- Clients reach the bid service through a load balancer.
- The bid service checks the current price in Redis, and records each accepted bid in the bid database.
Describe this diagram
Components
- clients (Client)
- lb (Load balancer)
- bid api (Service)
- current price (Redis)
- bid store (PostgreSQL)
Connections
- clients sends to lb
- lb sends to bid api
- bid api sends to current price
- bid api sends to bid store
Run it, then try raising the load and watch the bid database. A real design also routes each auction's bids to one place, which this slice leaves out.
The read path: item details come from a cache, and the current price from a small fast store updated on every accepted bid. Watchers receive price changes over a stream.
The write path: the bid is routed to the owner of that auction, validated against its current price and end time, and if accepted, appended to the bid history and applied to the auction in one transaction. The new price is then published to watchers.
The interesting problem: ordering bids on one auction
Two people bid $101 and $102 against a current price of $100 at nearly the same time. Both look valid when each is read alone. Only the order decides what happens: $101 then $102 leaves $102 as the leader, while $102 then $101 rejects the second bid.
Approach A: read the price, then insert the bid
Good: obvious and fine at 23 bids a second.
Bad: between the read and the insert, another bid can change the price. Two bids both validated against $100 are both accepted, and the history contains a bid that was never valid. This is the same check-then-act race as in the hotel and flash sale designs.
Approach B: a conditional update on the auction row
UPDATE auctions
SET current_price = ?, leader_id = ?, version = version + 1
WHERE id = ? AND status = 'open' AND ends_at > now() AND current_price + increment <= ?;
-- plus an INSERT into bids in the same transactionGood: the database decides atomically, and a stale bid simply changes zero rows. It is correct and simple.
Bad: every bid, including the many that lose, is a write attempt on one row. With 2,000 bids a second on a hot auction, the row lock queue grows and latency climbs for every bidder.
Approach C: one writer per auction
Route every bid for an auction, by auction id, to a single worker through a partitioned log or a consistent-hash router. That worker keeps the auction's current price in memory and processes bids one at a time in arrival order. A bid that does not beat the current price is rejected in memory and costs no database write. Only accepted bids are persisted, and in a flurry the great majority are rejected.
Good: a total order for free, no lock contention, and the cost of a rejected bid is microseconds. A hot auction only occupies its own partition.
Bad: the worker is a single point of failure for its auctions, so you need a standby that takes over from the persisted log, and routing must be consistent so two workers never own one auction.
The recommended answer is C for the bid decision, with B as the persistence step. In an interview, say it in this order: the correctness requirement is a total order per auction, a row can provide it but does not scale to a hot item, and a single writer per auction provides it while turning rejections into memory reads. For normal auctions, with 23 bids a second overall, plain B is enough, and many designs stop there. Mention that you would start with B and move hot auctions to C when measurements demand it.
Diagram, as text
- Bid with bidId leads to Route by auction id
- Route by auction id leads to Single writer for that auction
- Single writer for that auction leads to Persist bid and new price (beats price and before end)
- Single writer for that auction leads to Reject in memory (too low or too late)
- Persist bid and new price leads to Publish price to watchers
The second decision: ending the auction, sniping and automatic bids
Closing at exactly the right time. The auction's writer sets a timer for ends_at. When it fires, the writer marks the auction closed in the same serialized order as bids, so a bid is either before the close or after it, never both. If the worker crashes, a scheduler that scans for auctions past ends_at and still open (an index on ends_at) closes them. Closing is idempotent: closing a closed auction does nothing.
Sniping. Bidders who wait until the last second leave no time for a response. A common remedy is a soft close: a valid bid in the last two minutes extends the end by two minutes. It removes the advantage of the last-second bid at the price of auctions that can run long. Some marketplaces do not extend and state a hard end time, so say it is a product decision and give both.
Automatic bidding. A buyer enters a maximum. The system keeps the leader's maximum private and, when someone bids, sets the displayed price to just above the next-highest competitor (up to the leader's maximum), not to the maximum itself. This turns many bids into a few state changes inside the single writer, and it relies on the maximum being stored privately. In this model the winner pays about the second-highest bid plus an increment, an idea related to the second-price auction described by William Vickrey.
What watchers see. Pushing every accepted bid to 100,000 watchers is wasteful. Coalesce: publish at most one update per auction per second with the latest price, through a pub/sub layer that fans out to server-sent stream connections. Displaying a price that is one second old is fine, because the bid itself is validated against the real value. If a bid is rejected because the price moved, the response carries the fresh price.
Bottlenecks and failures
The hot auction. Handled by the single writer and by coalesced pushes. If the partition is overloaded, rate-limit bids per user (one bid per second per auction is a sensible limit) and reject excess quickly.
Writer failure. A standby takes over by replaying the auction's accepted bids from the log. Fence the old writer with an epoch number, so a paused writer that wakes up cannot accept a bid that the new writer has ordered differently.
Duplicate bids. A client retry after a timeout carries the same bidId. The writer remembers recent ids per auction, and the unique constraint on bid_id is the backstop, so a retry returns the first result.
Shill and sniping bots. Rate-limit per account, require verified accounts to bid, and flag patterns such as a seller's linked accounts bidding up their own item. Detection is a data problem and runs after the fact.
Time. All end-of-auction decisions use the owning writer's clock, and clients display a countdown synchronized to server time, not to the device clock.
What if the push layer is down? Watchers fall back to polling the price every few seconds. They see slightly older prices, but bids are still decided correctly, because the decision never depended on the push.
Trade-offs to name aloud
- Single writer per auction: strict order and cheap rejections, in exchange for a failover mechanism and consistent routing.
- Soft close: fairer last minutes, at the cost of unpredictable end times.
- Coalesced updates: watchers see a price up to a second old, in exchange for orders of magnitude less fan-out.
- Strong consistency for bids, eventual for the view: the decision is exact, while the display may lag slightly.
What interviewers listen for
- A working answer: an auctions table, a bids table, a rule that a bid must beat the current price, and a timer for the end.
- A strong answer: names the check-then-act race, serializes bids per auction with a conditional update or a single writer, makes bids idempotent with a client id, and decides the deadline on the server.
- A standout answer: computes the hot-auction rate and shows a row cannot take it, fences a replaced writer, designs the soft close and automatic bidding, and coalesces price pushes to watchers.
Check your understanding
Common mistakes
Validating a bid against a price you read earlier. Another bid may have landed since. Decide and apply in one step.
Using client time for the deadline. It can be wrong or manipulated. Use the owning server's clock.
Pushing every bid to every watcher. A hot auction turns into a message storm. Coalesce to about one update a second.
One database row for the whole system's hot items. It works until the first famous auction. Measure the hot-item rate and plan the single-writer path.
Forgetting to fence a replaced writer. A paused old writer can wake and accept bids out of order. Use an epoch number.
Storing only the current price. Keep every bid with a sequence number, for disputes, audits and replay after a failover.
Practice
In the final seconds of a popular auction, two users insist they bid before the deadline but were told the auction had closed. How does your design let you settle it?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Think about which events are in the record, and which clock decided.
Show a strong answer
Look at the ordered record. The auction's writer logs, for each bid, its received_at according to its own clock, and the close event is in the same sequence. The record shows whether each bid came before or after the close, and the order is the same for everyone.
Explain the rule. The deadline is decided by the receive time at the owning server, not by when the user pressed the button. Network delay is part of the user's experience, but the rule is the same for all bidders.
Reduce disputes. Show a countdown synchronized to server time, apply a soft close so a bid in the last two minutes extends the auction, and return a clear reason such as "closed at 12:00:00.000" in the rejection.
The pattern worth keeping: when a decision depends on time, make one authority own the clock, record its decision in an ordered log and tell users the rule up front.
The server that owns a hot auction crashes 30 seconds before the end. What must happen so no bid is lost and no bid is accepted twice?
Write your own answer first, on paper or in a note. Then compare.
Show a hint
Think about what is durable, who takes over and how you stop the old owner.
Show a strong answer
Make accepted bids durable first. The writer persists each accepted bid (and the new price) before it acknowledges to the bidder. The log is the record, and the in-memory price is a cache of it.
Take over by replay. A standby (or the next owner, by the routing table) loads the auction, replays accepted bids to rebuild the current price and leader, and starts accepting bids with the next sequence number.
Fence the old owner. Give each ownership term an epoch. Writes carry the epoch, and the store rejects a write from an older epoch, so a paused old writer cannot add a bid after the takeover.
Handle in-flight bids. Bids that were not acknowledged are retried by clients with the same bidId, so they are either found in the log (already accepted) or processed once by the new owner.
The pattern worth keeping: make state durable before acknowledging, rebuild by replay and fence the old owner with an epoch, so failover cannot create two sources of truth.
Key takeaways
- The average is easy and the last seconds of one auction are hard, so design for the hot item.
- Bids need a total order per auction, and the decision must be atomic with the price check.
- A single writer per auction keeps order and makes rejected bids nearly free. A conditional update is the simpler step before that.
- Decide the deadline on the owning server, and close in the same ordered stream as the bids.
- Soft close and automatic bidding are product choices to name, with their trade-offs.
- Coalesce price pushes and make bids idempotent with a client id.
Further reading
- William Vickrey, "Counterspeculation, Auctions, and Competitive Sealed Tenders", The Journal of Finance (1961): the second-price auction.
- Jay Kreps, Neha Narkhede and Jun Rao, "Kafka: a Distributed Messaging System for Log Processing", NetDB (2011): partitioned logs and per-partition ordering.
- Martin Kleppmann, "Designing Data-Intensive Applications" (O'Reilly, 2017): chapters on consistency, ordering and fencing tokens.