SDE & MLE Prep

Online Auction (eBay)

Requirements: list items with an end time; users place bids; a bid must beat the current highest; everyone watching sees the price update live; the highest bid at the end wins; bids must never be lost.

bid -> API (idempotency key) -> bids partitioned by auction_id (Kafka) -> bid processor (one per partition)
                                   -> conditional update: UPDATE auctions SET price=?, leader=? WHERE id=? AND price < ?
                                   -> bids log (all bids, durable) -> publish "new price" -> SSE to watchers
auction end: delayed job at end_time -> close auction -> notify winner -> payment

Deep dives

  • Consistency of the highest bid: either an atomic conditional update in the database (optimistic, retry on conflict) or serialize bids per auction through a partitioned queue (one consumer per auction → no races, natural ordering).
  • Durability: write every bid to a durable log before acknowledging; the auction's state can be rebuilt from it.
  • Real-time updates: SSE/WebSockets to watchers via pub/sub per auction; popular auctions have many watchers → two-level fan-out (pub/sub → gateway servers).
  • Ending correctly: use the server's timestamp for bid acceptance; close via a scheduled job (delay queue / timer wheel); many sites extend the end time after late bids to discourage sniping.
  • Proxy bidding: users give a maximum; the system bids the minimum increment on their behalf.