Design an Online Auction
How to design an online auction: ordering concurrent bids, pushing the highest bid to watchers, closing at an exact time, and what interviewers ask.
On this page
An online auction site lets sellers list items with a starting price and an end time, lets buyers place bids that must beat the current highest bid, and awards the item to the highest bidder when time runs out.
Interviewers ask it because of three hard problems: many people write to one record at once, every watcher should see the price within about a second, and the deadline must be exact. The steps below follow A Framework for Any Design.
Clarify the problem
Design an online auction site.
I'll assume the highest bid wins at a fixed end time, and that each bid must beat the current one by a minimum increment. Is that right?
Yes, that is the rule.
Do bids placed in the final seconds count, or does a late bid extend the auction?
Bids count up to the end time, and there are no extensions.
How many auctions are there, and how busy does the busiest one get?
About 1.5 million new auctions a day, each running for 7 days, with about 10 bids each on average. A popular auction can have 50,000 people watching it and hundreds of bids in its last ten seconds.
Then two bids can never both win, an accepted bid is never lost, one clock decides whether a bid is on time, and watchers see a new high bid within a second.
The functional requirements are creating an auction with a starting price, a minimum increment and an end time, placing bids, seeing the highest bid live along with the bid history, and notifying the winner and the seller when the auction closes. The non-functional requirements are strict ordering of bids on one auction, durable accepted bids, rejection of bids after the end time, new high bids reaching watchers within 1 second, and the site staying up while a popular auction ends. Payment, shipping, search, fraud detection, buy-it-now and reserve prices are out of scope.
Estimate the scale
- Bid rate: 1.5 million auctions × 10 bids is 15 million bids a day, or about 170 bids a second on average. Evening endings make the peak about 10 times that, or 1,700 bids a second.
- Page reads: at about 100 page views per bid, reads run at about 17,000 a second, which caches serve.
- Storage: bids of about 100 bytes add about 550 GB a year, and auctions of about 2 KB add about 1.1 TB a year. Photos go in blob storage.
- The busiest auction: 500 bids in its last 10 seconds is 50 bids a second, and every one of them updates the same row.
If every accepted bid on the hot auction is pushed to every watcher, how many messages a second is that?
- 50 accepted bids a second
- 50,000 people watching
Show the working
- 50 bids × 50,000 watchers = 2,500,000 messages a second
- Sending at most 4 updates a second (one every 250 ms) gives 4 × 50,000 = 200,000 messages a second
Estimate 2.5 million/s (anything from 800 thousand/s to 8 million/s is a good answer)
Bids on one auction update a single row, one at a time. At most how many bids a second can that auction accept?
- One row per auction, and bids on it run one at a time
- About 2 ms per bid while the row is locked, including the write to a synchronous replica
Show the working
- 1 second ÷ 2 ms = 500 bids a second
- The hot auction needs 50 bids a second, which is 10% of that ceiling
Estimate 500/s (anything from 150/s to 1.5 thousand/s is a good answer)
Write the calls to create an auction, place a bid and watch an auction. Decide what a bid returns when it is too low or too late.
Compare with a model answer
A bid is a POST that carries a client-generated id and is answered immediately with one of three results: accepted, outbid (with the new minimum) or ended. Watching is a one-way stream from the server, so server-sent events are enough.
Define the API Optional
Optional in the interview. Sketch the API only if the interviewer asks, if an API choice shapes the design, or if time permits. Otherwise say "I'll skip the detailed API unless you want it" and go to the data model.
POST /auctions
body: { "title": "...", "start_cents": 5000, "increment_cents": 500,
"end_at": "2026-11-15T20:00:00Z" }
201 { "auction_id": 812 }
GET /auctions/{id}
200 { "high_cents": 11000, "min_next_cents": 11500, "high_bidder": "an***",
"seq": 36, "end_at": "...", "server_time": "2026-11-15T19:58:02.120Z" }
POST /auctions/{id}/bids
body: { "bid_id": "b-1", "amount_cents": 12000 }
201 { "status": "accepted", "seq": 37 }
200 the same body again a retry with the same bid_id
409 { "status": "outbid", "min_next_cents": 12500 }
410 { "status": "ended" }
GET /auctions/{id}/live text/event-stream
event: high data: { "seq": 37, "high_cents": 12000, "min_next_cents": 12500 }
event: ended data: { "winner": "an***", "final_cents": 12000 }
GET /auctions/{id}/bids?before_seq=37&limit=20 history, newest firstThe decision worth arguing is that a bid gets its answer in the same request, because a bidder in the last seconds needs to know at once whether to bid again. The bid_id is the bid's idempotency key: if a phone loses the response and retries, the server finds the stored bid and returns its original result. The server_time field lets the browser run its countdown against the server's clock.
Sketch the auction and bid tables. Decide where the current highest bid is stored and how every bid is kept.
Compare with a model answer
The auction row holds the current high bid, the next minimum and a bid counter. Each accepted bid is appended to a bids table in the same transaction, numbered by that counter.
Model the data
auctions
auction_id BIGINT PRIMARY KEY
seller_id BIGINT
title VARCHAR(200)
increment_cents BIGINT
end_at TIMESTAMP
status VARCHAR(8) -- open | closed
high_cents BIGINT NULL
high_bidder_id BIGINT NULL
min_next_cents BIGINT -- starts at the starting price
bid_count INT -- also the last bid's seq
INDEX (status, end_at) -- for the closer
bids
auction_id BIGINT
seq INT -- 1, 2, 3 ... per auction
bid_id VARCHAR(40) -- from the client
bidder_id BIGINT
amount_cents BIGINT
placed_at TIMESTAMP
PRIMARY KEY (auction_id, seq)
UNIQUE (auction_id, bid_id)Every write touches exactly one auction, so a relational database partitioned by auction_id fits, with each auction's bids stored next to the auction. A bid is then a transaction inside one partition. The site keeps every accepted bid, not only the highest, because the record of each bid settles disputes. Rejected attempts go to a separate log for fraud checks.
Decide where bids are checked and written, how a new high bid reaches 50,000 browsers, and what closes an auction.
Compare with a model answer
An auction service runs the conditional write and publishes each new high bid to a topic for that auction. Live servers hold the browsers' streams and subscribe to the topics. A closer worker closes auctions that are past their end time and triggers the notifications.
High-level design
request and replyasynchronous message
- high
- $110
- min next
- $115
- seq
- 36
150,000 browsers are watching auction 812 through the live servers. The high bid is $110 and the next bid must be at least $115.
- high
- $120
- min next
- $125
- seq
- 37
2At 19:59:58.100 Ana bids $120. One update succeeds only if the auction is open,
end_atis in the future and $120 is at least $115. One row changes, so bid #37 is committed.- high
- $120
- min next
- $125
- seq
- 37
3Ben also bid $120 in the same millisecond. His update waited for Ana's row lock, then re-checked and found that $120 is below the new minimum of $125. Zero rows change, so he receives a 409.
- high
- $120
- seq
- 37
- watchers
- 50,000
4After the commit, the service publishes seq 37 to the topic for this auction. Each live server receives one copy and pushes it to its own watchers within about 250 ms.
- shown seq
- 37
- late message seq
- 36
5At 19:59:59.990 a live server dies. Its viewers reconnect and receive a snapshot at seq 37, and a delayed message for seq 36 is ignored because 36 is lower than 37.
- high
- $120
- seq
- 37
- clock
- 20:00:00.040
6At 20:00:00.040 Dan's bid of $140 arrives 40 ms late. The closer has not run yet, but
end_at > now()is already false in the bid's own update, so zero rows change and Dan receives a 410.- status
- closed
- winner
- Ana
- price
- $120
7At 20:00:01 the closer sets auction 812 to closed, but only if it is still open. One row changes, so this closer owns the close, and Ana wins at $120.
- status
- closed
- winner
- Ana
- price
- $120
8The closer then emits a single "auction ended" event. The winner and the seller are notified, and every watcher receives an
endedmessage.
Deep dives
Ordering concurrent bids on one auction
The problem is that two bids can arrive together, and each must be judged against the true current high bid. The simplest code reads the high bid, compares the new amount in the application, and writes. With two concurrent bids, both read "the high bid is $110", both decide they are valid, and the second write overwrites the first. One bid is silently lost. The options below prevent this and differ in how long the row stays locked.
Lock the row, then check in code
The service starts a transaction, runs SELECT … FOR UPDATE on the auction row, checks the bid in application code, writes the update and commits. It can express any rule, because the check runs in the application. The cost is that the lock is held across at least two round trips, so the auction accepts fewer bids a second.
One conditional update
The whole rule goes into the WHERE clause of a single update: the auction is open, the deadline has not passed, and the amount is at least the minimum. The database takes the row lock, evaluates the condition against the latest committed version of the row, and either writes or changes nothing. The lock lasts about 2 ms and no application code runs inside it. The limitation is that the rule must fit in a WHERE clause, and a rejected bid needs a follow-up read to say why.
One owner per auction
A single server owns each auction, keeps its state in memory, appends every bid to a durable log before replying, and applies bids one after another. It can handle thousands of bids a second on one item. The difficulty is failover: a new owner must take over, and the old one must stop accepting bids even if it is only slow and not dead, which needs leases and fencing tokens.
| Option | Good at | Bad at | Pick it when |
|---|---|---|---|
| Lock the row first | Any rule can be checked in code, and the code is easy to read. | The lock is held across several round trips, which lowers the bids a second. | The check is too complex for one WHERE clause, such as automatic proxy bidding. |
| Conditional update Usual default | One statement checks and writes, and the lock lasts about 2 ms. | The rule must fit in a WHERE clause, and a rejected bid needs a follow-up read to explain why. | A single auction receives up to a few hundred bids a second, which is the case here. |
| One owner per auction | It handles thousands of bids a second on one item. | Failover needs leases and fencing tokens so the old owner stops accepting bids. | A single item receives thousands of bids a second. |
This design uses the conditional update. The statement below places bid #37 from the tracer.
WITH won AS (
UPDATE auctions
SET high_cents = 12000, high_bidder_id = :ana,
min_next_cents = 12000 + increment_cents,
bid_count = bid_count + 1
WHERE auction_id = 812 AND status = 'open'
AND end_at > now() AND 12000 >= min_next_cents
RETURNING bid_count -- 37
)
INSERT INTO bids (auction_id, seq, bid_id, bidder_id, amount_cents, placed_at)
SELECT 812, bid_count, 'b-1', :ana, 12000, now() FROM won;
-- 1 row inserted: accepted as #37
-- 0 rows: read the auction to answer "outbid" or "ended"Checking the bid against a cached or pushed price and then writing would reopen the race, so the cache is only for display and the check runs inside the atomic write. The row lock is the point where bids are put in order, and the seq numbers follow the order in which the lock was granted. Ticket booking uses the same conditional update and covers the isolation details.
In PostgreSQL, now() returns the time the transaction started, so a bid that reached the database before the end time but waited for the lock still counts. The service looks up bid_id before the update so that retries get the stored answer, and the unique key on (auction_id, bid_id) stops two racing copies of the same bid, because the statement fails as a whole and the update is rolled back with it. If a single item reached 5,000 bids a second, the next step would be one owner per auction, and you should state its failover cost.
Showing the highest bid live
The problem is to get every new high bid to as many as 50,000 watchers within a second without the database seeing those watchers. Watchers only receive data, so server-sent events fit well: they are plain HTTP and reconnect automatically. As in the stock trading app, the auction service publishes each accepted bid to a topic for that auction, each live server subscribes to the topics its watchers care about, and each server pushes to its own connections.
Out-of-order messages
Every update carries the auction's seq, and the browser keeps only the highest seq it has seen. Two messages, or a reconnect snapshot and a delayed message, can arrive in either order. Without this rule the screen could show an older price.
Send the latest state in batches
Each message contains the full current high bid, so skipping some loses nothing. A live server sends at most one update per auction every 250 ms, so the hot auction produces 200,000 messages a second instead of 2.5 million.
Closing exactly at the end time
The obvious design is a timer that closes the auction at 20:00:00. The problem is that timers fire late, and if closing is what stops bidding, a slow timer lets late bids in. The fix is to enforce the deadline inside the bid's own write, with end_at > now(), judged by the database clock that owns the row. The closer then only records the winner and sends notifications, and it can run several seconds late without changing the outcome.
About once a second the closer finds due auctions through the (status, end_at) index and runs SET status = 'closed' WHERE auction_id = 812 AND status = 'open' AND end_at <= now(). Only the closer whose update changes one row emits the "ended" event, so nobody is notified twice even with several closers running.
Hard close
With a hard close, bids count until the end time and then stop. The rule is one condition in the WHERE clause. The drawback is that it rewards last-second bidding, and a bidder on a slow connection can lose a race they never saw.
Soft close
With a soft close, a bid placed in the last 2 minutes moves end_at to 2 minutes after that bid, so other bidders have time to respond. It fits into the same update with end_at = GREATEST(end_at, now() + interval '2 minutes') in the SET clause. The costs are that the countdown and the closer must handle a moving end time, and an auction can run long.
Bottlenecks and failures
The estimate gave a peak of 1,700 bids a second. If traffic grows tenfold, that becomes 17,000 bids a second and 170,000 page reads a second. Adding partitions handles the bids, and the CDN and caches handle the reads. The one limit that partitioning cannot fix is a single item at its ceiling of 500 bids a second, and that is the point at which one owner per auction becomes worth its failover cost. The hot auction at 50 bids a second is far below that ceiling, and its real load is its 50,000 viewers, which live servers absorb.
| When this dies | What happens | What you do |
|---|---|---|
| An auction server | Bids in flight get no response; committed bids are safe. | The browser retries with the same bid_id and receives the real result. |
| The database primary | Bids on its auctions fail until a replica takes over. | Replicate synchronously so no acknowledged bid is lost, and reject bids during failover. |
| A live server | Its viewers' streams drop. | Browsers reconnect, receive a snapshot with its seq, and ignore older messages. |
| The pub/sub, or a lost publish | Screens stop updating, but bids still work. | Each message holds the full state, so the next one repairs a loss. |
| The closer | Auctions stay open after their end time. | The bid's write still checks the deadline. Restart the closer and it catches up. |
What a strong answer sounds like
| Level | What the answer does |
|---|---|
| Junior | Checks the bid in application code and then writes it. |
| Mid | Uses a conditional update, keeps every bid, streams highs, and closes with a scheduled job. |
| Senior | Puts the deadline in the bid's own write, orders pushes by sequence number, makes bids idempotent, and asks whether the close is hard or soft. |
A bid arrives 40 ms after the end time. What happens?
The bid's own write rejects it, because the update requires end_at > now() according to the database clock that owns the auction. The closer only records the winner and sends notifications, so it could run several seconds late and the result would be the same.
Isn't that unfair to someone on a slow connection?
Yes, with a hard close the arrival time decides. That is why I asked about a soft close, which fits into the same update.
Follow-up questions
How would you support automatic bidding up to a maximum?
Each bidder stores a secret maximum and the visible price becomes the second-highest maximum plus one increment, capped at the highest maximum. That needs several values read together and does not fit in one WHERE clause, so lock the row, compute the result in application code and write it in one short transaction. Locking the row first is the right option here.
How do you stop a seller from bidding up their own item?
The bid's write rejects the seller's own account with one extra condition. Shill bids from other accounts can only be found afterwards by analysing bid history.
How do you tell a bidder they were outbid after they left the page?
The auction service publishes an "outbid" event for the previous high bidder, and the notification system sends a push message or an email. Notifications are rate-limited so that a bidding war does not flood the bidder.
How would you run this in several regions?
Each auction has one home region where its bids are written, and bidders elsewhere pay the extra round trip. Accepting writes in several regions would need cross-region agreement on every bid.
Why not put every bid on a queue and process them in order?
A queue partitioned by auction does give a single ordered stream per auction, and one consumer per partition is the same idea as one owner per auction. It does not remove the need for a conditional write, because the bidder still needs an immediate accepted or rejected answer, and a consumer that is slow or restarts can replay a bid.
After your attempt, tick what you really did. Be strict: "I thought about it" is not "I said it out loud".