Design an online auction 00:00:00 Make a prediction You will compute a proxy-bidding result, keep private maximum bids separate from public price, and settle a race at closing time. The auction opens at ten dollars. Ana's maximum is twenty and Ben's is fifteen, with a one-dollar increment. Under the simple second-highest-plus-increment rule, does Ana immediately pay twenty? No. Ana leads at sixteen dollars, capped by her maximum and subject to the announced reserve and increment rules. Her maximum is authorization to bid up to twenty, not the displayed winning price. 00:00:39 A village sells a cow by candle At a village auction each buyer gives the auctioneer a folded note with their limit. The public board changes only as competition requires. Once the closing candle goes out, a late note cannot quietly rewrite the winner. The notes are private maxima, the board is derived price, and the closing event freezes the accepted state. Tie-breaking and deadline rules must be declared in advance. An online auction sells one lot to whoever offers most. In the common form people write the most they would pay, and the system bids for them: the visible price is just above the second-highest maximum. It is a popular exercise because the naive version fails in public. Two bids at once, a bid in the last second, a timer thread: each gives a wrong winner. 00:01:28 Update price and leader atomically An auction starts at ten dollars with a one-dollar increment. Ana sets a maximum of twenty. Ben sets a maximum of fifteen. Under a simple proxy-bidding rule, Ana leads at sixteen, subject to the agreed reserve and increment rules. Store bidders' private maxima separately from the public current price. Update rank and price together, with an explicit rule for equal maxima. Closing freezes the winner according to the deadline and that rule. A late bid must not silently change an auction already settled. Give Bo and Cam valid bids based on the same displayed price. Serialize each acceptance with the price and leader update, then tell each caller the outcome. Independently updating amount and bidder can combine one person's amount with the other's name, a state no legal bid produced. 00:02:20 A racing close and bid A bid arrives at the closing instant while another thread is finalizing the winner. Define the clock rule, then serialize acceptance and close on the auction. Test a bid just before the deadline and one exactly at it so the observed winner follows a stated policy. A bid arrives near closing and waits behind another decision. Use the clock where acceptance is serialized to assess whether it is still admissible. Once the close commits, later execution cannot change the frozen result. Specify how equal bids are ordered separately from how time is checked. Two equal maximum bids need a rule such as earliest accepted bid, and a bid exactly at closing needs a time convention. Leaving either to thread scheduling makes results inconsistent. A simple highest-bid auction has different pricing semantics; confirm the auction format before implementing increments or proxy bidding. eBay: automatic bidding. Bidders enter the highest price they would pay, and the site bids for them in increments, only up to that limit. The help page explains why somebody can be outbid at once. Solidity: simple open auction. The documentation's contract has a highest bid, a fixed end and an ended flag. Beaten bidders withdraw their money themselves, because calling foreign code while deciding is a risk. 00:03:50 Try an interview follow-up Why is the clock read under the lock? Because a time that was read before waiting is old when the decision is made. A bid could read 599.9, wait until 600.2 and be accepted, after others were refused. Reading inside makes the order of times equal to the order of decisions. Two valid bids reach an auction at the same recorded time. What determines the winner? Agree on a tie-breaker and whether a bid at the closing instant is admissible. Serialize acceptance at the auction boundary and preserve the resulting order. Replay the same history and confirm the same winning bid. 00:04:34 What to take with you Each lot has one owner with one lock. A bid is checked, numbered, settled and answered in one block, with the clock read inside. The price is one step above the best of the others, capped by the leader's maximum and lifted to the reserve. Late bids move the end in the same block, the closer only asks. Views are frozen, secret-free and versioned, and listeners hear them after the lock. The list of bids is the truth from which any standing can be computed again.