Skip to content

How to design an online auction

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

An online auction lets a seller list an item with a starting price and an end time, lets buyers bid against each other while it runs, and hands the item to the highest bid when the clock runs out. Most of the 10 million live auctions are quiet; the popular ones draw a crowd that bids and watches in the final minute, and one bid at a time can be highest. The answer turns on making the check against the highest and the write of the new bid one atomic step inside the database, storing each bid before the bidder hears anything, and pushing new highs to watchers through a channel for just that auction.

Clarifying questions

AskWhy it mattersA typical answer

Do bids race live, with the current highest visible, or are they sealed and opened at the end?

A live race is where the concurrency problem lives: two bids in the same millisecond on one auction. Sealed bids remove it and turn the question into a batch job at the close.

Live: the current highest is shown, a new bid must beat it, and the highest when time runs out wins.

Does a bid have to beat the highest by a minimum increment, and do we need automatic bidding up to a maximum?

Both change what the compare step looks at. An increment is a rule in the compare; a hidden maximum is extra state on the auction row that the same transaction must update.

Start with 'strictly higher than the current highest'. Increments and automatic bidding are extensions to mention, not build.

How many auctions run at once, and how are bids spread across them?

It decides whether the hard part is throughput across many auctions or contention on a few. The shape here is a long tail: most auctions quiet, a handful with crowds.

About 10 million running at once, most with a few bids, and a crowd bidding on the popular ones in the final minute.

How fresh does a watcher's view of the highest bid need to be?

'Near real time' pushes toward a push channel over a page that refreshes on a timer, and brings the connection state that comes with it.

Near real time: a watcher in the final minute should see a new highest promptly, not on their next manual refresh. If you want a number, propose one and have it confirmed.

Is the end time fixed, or does a bid in the final moments extend the auction?

A fixed end time makes the close a simple job. An extension means the end time moves while bids are landing, and the close has to read the moved time.

Fixed for the base design. Expect a follow-up asking how you would stop last-second sniping with an extension.

Who has to be told when an auction closes, and how quickly?

Notifying the winner is a core requirement; notifying the seller and the outbid is nice to have. The speed sets whether the close can run as a batch or must fire at the end time.

The winner, promptly after the end time; propose a target and have it confirmed. Payment and handover are out of scope.

Is browsing, searching or bid history part of this round?

Search and history are read paths with their own indexes. Confirming they are out lets you spend the time on bidding, live updates and the close.

Out of scope: search, category filters, sorting by price and a bid history view.

The requirements menu

RequirementScopeWhy

Post an item for auction with a starting price and an end time

Core

The listing creates the auction row that bids, watchers and the close all key on, and the end time stored here is what the close later reads.

Bid on an item; a bid must beat the current highest bid

Core

The write path that carries the hard problem: two bids on one auction in the same instant, and a rule that one of them has to lose.

View an auction with its current highest bid, updated live

Core

The read path, and the one that fans out: a popular auction has a crowd of watchers who all want the same new number at once.

Close the auction at its end time and notify the winner

Core

The moment that decides who wins. It has to agree with the bid path about which bids arrived in time.

Automatic bidding up to a hidden maximum

Optional

Worth naming: it changes the auction row (a hidden maximum per leader) and the compare step, but not the shape of the design. Build it if the interviewer asks; otherwise say where it would go.

Extend the end time when a bid lands in the final moments

Optional

The anti-sniping rule. Leave it out of the base design so the close stays simple, and be ready to add it: it is a likely follow-up and it changes what the close must read.

A reserve price below which the item does not sell

Optional

A seller feature that is cheap to add: one column and one check at the close. Mention it and move on unless asked.

A seller canceling an auction before it ends

Optional

Useful in a real product, and it reuses the close path with a different status. Take it if time allows; it costs little.

Retracting a bid after it is placed

Out of scope

A policy question more than a design one. It complicates the highest-bid rule (the second highest has to be restored), so park it unless the interviewer wants it.

Payment and checkout after the win

Out of scope

A separate system with its own consistency problems. Say the close emits an event a payment service could consume, then stop.

Searching for items

Out of scope

Needs an inverted index and its own pipeline. Not where this question's difficulty is.

Filtering by category

Out of scope

A catalog concern, not an auction one; it would share the search index.

Sorting by price

Out of scope

Also a catalog read path. Name it as a listing-side feature and leave it.

Viewing an item’s bid history

Out of scope

The data exists, because each bid is stored as a row, so this is a read path you could add later without changing the design.

Non-functional requirements

RequirementWhat it forces

Bids are strongly consistent: two bids never both win

The comparison with the highest and the write of the new bid happen as one atomic step in the database that owns the auction, with the stored highest on the same row. No cache, replica or application-side read may stand in for that check.

No accepted bid is ever lost

A bid is written as its own row, replicated to a second node, and the bidder is told the outcome after that, not before. The bids table doubles as the log the highest can be rebuilt from.

Watchers see a new highest bid in near real time

A push channel from the bid service to the watchers' browsers (SSE here), fed by a per-auction publish channel, and realtime servers that hold connection state and subscribe for the auctions their watchers follow.

About 10 million auctions running at once (Hello Interview)

The data set is small enough for one node, so the split is by auction id for failure isolation and for the write peak when many auctions close in the same minute. The design must stay cheap for the quiet majority: no per-auction process, no channel with no subscribers.

Estimates

QuantityWorkingResultWhat it sizes

Bids stored across all live auctions

10 million auctions × about 10 bids each (the brief says most have a few; 10 is a round average that leaves room for the popular ones) = 100 million bids

About 100 million bid rows

The bids table, which is also the log the highest can be rebuilt from.

Storage for auctions and bids

100 million bids × about 100 bytes (ids, amount, time, idempotency key) = 10 GB; 10 million auctions × about 500 bytes (ids, prices, times, status, with room for indexes) = 5 GB

About 15 GB in total

Whether size forces a split: it does not, so partitioning is about the write peak and failure isolation, not disk.

Average bid rate

100 million bids spread over an assumed auction length of one week: 100,000,000 ÷ 604,800 seconds ≈ 165 bids a second

About 165 bids a second on average

The quiet baseline. The average is small; the design is shaped by the peak and by correctness.

Write peak when many auctions close together

Assume 1% of auctions, 100,000, end in the same minute, and each takes 10 bids in that minute: 1,000,000 bids ÷ 60 seconds ≈ 16,700 bids a second

About 16,700 bids a second, roughly 100 times the average

The write load the partitions share, and the reason to partition by auction id at all.

Contention on the hottest auction row

A crowd placing 100 bids in the final minute on one auction: 100 ÷ 60 seconds ≈ 1.7 writes a second on one row

Under two writes a second on the hottest row

Why a row lock per auction is not the bottleneck even for a popular auction, and why a hot auction can stay on one partition.

Fan-out from one popular auction

10,000 watchers × 100 bids in the final minute = 1,000,000 messages a minute, about 16,700 a second, for one auction

About 16,700 pushes a second from a single auction

The realtime layer: this load lands on the servers holding those watchers' connections, which is why watchers are spread by connection and each server subscribes per auction.

Polling cost against push

Assume 1 million concurrent watchers across all auctions, each re-reading once each 2 seconds: 1,000,000 ÷ 2 = 500,000 reads a second, many of them for auctions whose highest has not changed since the last read

About 500,000 reads a second for polling; push sends one message per accepted bid per watcher instead

Why the live view is a push channel and not a timer.

Database nodes for the write peak

16,700 bids a second at peak ÷ a budget of about 2,000 writes a second per node (state this as your assumption; each write is a short transaction that also waits for a replica) ≈ 9 partitions; with a synchronous replica each, about 18 nodes

About 9 partitions, about 18 nodes with replicas

How many database nodes 10 million live auctions need: a small cluster, sized by the closing-minute peak rather than by data.

Core entities

EntityWhat it holds

Item

What is being sold: the seller's description and photos, separate from the auction so the same item could be relisted.

Auction

The row bidders race over: one per listing, holding the end time and the current highest, which is why the bid service locks it.

Bid

One row per bid attempt, accepted or rejected, so the table is both the history and the log the highest can be recomputed from.

User

Sellers and bidders. Accounts are ordinary; the design keeps an id and a public handle to show next to a bid.

The API

EndpointNotes

POST /auctions { item, starting_price, end_time } → { auction_id }

Handled by the auction service. It checks that the end time is ahead and the starting price is positive, inserts the auction as open with no highest bid, and returns 201 Created. In this design the end time stored on this row is the one the bid service and the close read later.

POST /auctions/{id}/bids { amount } → accepted or rejected with the current highest bid

Handled by the bid service. The client sends an Idempotency-Key header it generated. The service runs one transaction (status open, end time ahead, amount above the highest, write the bid row, update the highest) and replies after the commit is confirmed by the replica: 200 OK with accepted true, or 409 Conflict with accepted false and the current highest. After the end time it returns 410 Gone. A retry with the same key returns the stored outcome instead of a second bid.

GET /auctions/{id} → auction with the current highest bid

One read by primary key. In this design the auction page would call it on load and then follow the stream. Serve it from the partition's primary when the caller is about to bid, so the number they are beating is current; a replica is fine for a casual look.

GET /auctions/{id}/live → SSE stream of new highest bids

A text/event-stream response held open by a realtime server, which subscribes to this auction's channel for as long as it has a watcher. In this design we'd put the new highest amount, the leader's public handle and the current end time in each event, with an id so a reconnecting browser can tell what it already saw and re-read the auction once.

The high-level design

createbidinsertupdateClientAuction serviceBid serviceAuctions DB

Step 1 of 4

Listings and bids on one database

Start with the two write paths. An auction service takes POST /auctions and inserts the auction row. A bid service takes POST /auctions/{id}/bids and runs the whole decision as one database transaction: lock the auction row, check status and end time, compare the amount with the stored highest, write the bid row, update the highest if it won, commit, and then reply. The bid row is written whether it won or lost, so the bids table is a record of what happened, not a cache of it. Both services write to one database for now, about 15 GB in the estimate, which fits one node. What this step lacks: a watcher learns about a new highest when they reload the page.

createbidinsertupdateacceptedSSEduewinnerreplicateClientAuction serviceBid serviceAuctions DB byauction idPub/sub perauctionRealtime serversWatchersClose jobNotificationserviceSync replica
The whole design

What breaks first

The deep dives

Concurrent bids. Two bidders hit the same auction in the same millisecond, one at 101 dollars and one at 102. How does the bid service make sure 102 ends up on top whichever arrives first, and what does each bidder see, including after a lost reply?

A concept that helps here: Optimistic and pessimistic lockingA concept that helps here: Idempotency keys

Live updates and the close. A crowd is watching one auction that ends at noon, and bids are landing each second. How does each new highest reach the watchers, how does the design decide which bids made it before noon, and what changes if a late bid pushes the end time back?

A concept that helps here: WebSockets, server-sent events and pollingA concept that helps here: Routing messages between stateful serversA concept that helps here: Clocks and ordering

Ten million auctions. With 10 million auctions live at once, how do you split the auctions and their bids across machines, what happens to the one auction everyone is bidding on, and which bids survive when the node holding it dies mid-bid?

A concept that helps here: Sharding and partition keysA concept that helps here: Hot keys and hot partitionsA concept that helps here: Replication and read replicas

Concepts this guide uses

Sources

  1. PostgreSQL documentation: Explicit Locking (row-level locks, FOR UPDATE)
  2. PostgreSQL documentation: Replication configuration (synchronous_standby_names)
  3. Stripe API reference: Idempotent requests
  4. MDN: Using server-sent events
  5. Redis documentation: Pub/sub
  6. Confluent documentation: Kafka replication and committed messages
  7. eBay Help: Automatic bidding
  8. eBay Help: Bid sniping
  9. Ultimate Auction: What is auction sniping and how soft close stops it
Sign in to report a mistake