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
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Concurrent bids
- Live updates and the close
- Ten million auctions
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
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
| Ask | Why it matters | A 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. |
Non-functional requirements
| Requirement | What 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
| Quantity | Working | Result | What 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| 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 |
| Handled by the bid service. The client sends an |
| 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. |
| A |
The high-level design
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.
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: Atomic read-modify-write
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?
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?
Concepts this guide uses
Sources
- PostgreSQL documentation: Explicit Locking (row-level locks, FOR UPDATE)
- PostgreSQL documentation: Replication configuration (synchronous_standby_names)
- Stripe API reference: Idempotent requests
- MDN: Using server-sent events
- Redis documentation: Pub/sub
- Confluent documentation: Kafka replication and committed messages
- eBay Help: Automatic bidding
- eBay Help: Bid sniping
- Ultimate Auction: What is auction sniping and how soft close stops it