Back to explorer
System Architectures• 45 Min

Design an Online Auction System (eBay / Real-Time Bidding)

HARD

Design an Online Auction System (eBay / Real-Time Bidding)

Online auction systems allow sellers to list rare items for timed bidding. As the countdown clock ticks toward zero, hundreds of eager buyers engage in "bid sniping" (submitting bids in the final seconds), demanding atomic concurrency control and instant broadcast updates.


1. System Requirements

Functional Requirements

  1. Create Listings: Sellers specify item details, reserve price, starting bid, and auction end timestamp.
  2. Place Bids: Buyers place bids higher than the current highest bid + minimum increment.
  3. Real-time Price Broadcast: All users viewing the auction see the updated leading bid within $< 200\text{ms}$.
  4. Sniping Protection / Soft Close: If a bid is submitted in the final 2 minutes, auto-extend the auction by 2 minutes to prevent bot exploitation.
  5. Auction Settlement: When the timer expires, the highest bidder wins and enters the payment checkout flow.

Non-Functional Requirements

  1. Strict Bid Consistency: Exactly one leading bid at any price point; race conditions must never record overlapping winners.
  2. Sub-second Latency: Bid placement must acknowledge in $< 50\text{ms}$.
  3. High Availability: 99.99% availability during high-traffic auction closes.

2. Concurrency & Bid Placement Engine

Handling 10,000 users bidding simultaneously in the last second requires memory-speed atomic transactions:

lua
-- Redis Lua Script: Atomic Bid Verification & Update
local auction_id = KEYS[1]
local new_bid = tonumber(ARGV[1])
local user_id = ARGV[2]

local current_bid = tonumber(redis.call('HGET', auction_id, 'highest_bid') or '0')
local end_time = tonumber(redis.call('HGET', auction_id, 'end_time'))
local now = tonumber(ARGV[3])

if now > end_time then
    return {err = "AUCTION_CLOSED"}
end

if new_bid > current_bid then
    redis.call('HSET', auction_id, 'highest_bid', new_bid, 'highest_bidder', user_id)
    -- Extend time if bid placed in last 2 minutes (120 seconds)
    if (end_time - now) < 120 then
        redis.call('HSET', auction_id, 'end_time', end_time + 120)
    end
    return {ok = "BID_ACCEPTED"}
else
    return {err = "OUTBID"}
end

Key Architecture Trade-Offs & Decision Matrix

Decision FactorChoice AChoice BSelected Architectural Rationale
Communication ProtocolREST over HTTP/2WebSockets / gRPCUse REST for stateless CRUD APIs; use WebSockets for low-latency bidirectional streaming.
State ManagementCentralized Distributed StoreLocal Memory with Sticky SessionsCentralized Redis / Database state allows seamless container auto-scaling and zero-downtime rolling deploys.
Concurrency ControlOptimistic Locking (version column)Pessimistic Locking (SELECT FOR UPDATE)Optimistic locking delivers superior throughput for low-conflict consumer operations.