Design Online Auction

System Design Challenge

hard
45-60 minutes
bidding-enginereal-time-updatespayment-processingfraud-detectiontime-synchronization

Design Online Auction

What is Online Auction?

An Online Auction is a real-time platform that allows users to bid on items with time-limited auctions. It's similar to eBay, Sotheby's online auctions, or government auction platforms. The service provides real-time bidding, bid validation, and auction management.

Real-time bidding with high-frequency concurrent updates and strict time synchronization is what makes systems like Online Auction unique. By understanding Online Auction, you can tackle interview questions for similar real-time platforms, since the core design challenges—real-time updates, bid validation, auction state management, and consistency—remain the same.


Functional Requirements

Core (Interview Focussed)

  • Real-time Bidding: Users can place bids in real-time during auctions.
  • Bid Validation: Validate bids for amount, timing, and user eligibility.
  • Auction Management: Create, manage, and monitor auctions.
  • Real-time Updates: Broadcast bid updates to all participants.

Out of Scope

  • User authentication and accounts
  • Payment processing and escrow
  • Item catalog and search
  • Seller tools and analytics
  • Mobile app specific features

Non-Functional Requirements

Core (Interview Focussed)

  • Low latency: Sub-second response time for bid placement.
  • High availability: 99.9% uptime during active auctions.
  • Consistency: Ensure bid order and auction state consistency.
  • Scalability: Handle thousands of concurrent bidders per auction.

Out of Scope

  • Data retention policies
  • Compliance and privacy regulations

💡 Interview Tip: Focus on low latency, high availability, and consistency. Interviewers care most about real-time bidding, bid validation, and auction state management.


Core Entities

EntityKey AttributesNotes
Auctionauction_id, item_name, start_time, end_time, statusIndexed by status for active auctions
Bidbid_id, auction_id, user_id, amount, timestampIndexed by auction_id for bid history
Useruser_id, username, email, bid_limitUser account information
AuctionStateauction_id, current_bid, bid_count, time_remainingReal-time auction state
BidHistoryauction_id, bid_id, amount, timestamp, user_idComplete bid history

💡 Interview Tip: Focus on Auction, Bid, and AuctionState as they drive real-time bidding, bid validation, and state management.


Core APIs

Auction Management

  • POST /auctions { item_name, start_time, end_time, starting_price } – Create a new auction
  • GET /auctions/{auction_id} – Get auction details
  • GET /auctions?status=&limit= – List auctions with filters
  • PUT /auctions/{auction_id}/end – End an auction

Bidding

  • POST /auctions/{auction_id}/bids { amount, user_id } – Place a bid
  • GET /auctions/{auction_id}/bids – Get bid history
  • GET /auctions/{auction_id}/current-bid – Get current highest bid

Real-time Updates

  • GET /auctions/{auction_id}/stream – WebSocket stream for real-time updates
  • POST /auctions/{auction_id}/subscribe – Subscribe to auction updates
  • POST /auctions/{auction_id}/unsubscribe – Unsubscribe from updates

High-Level Design

System Architecture Diagram

Key Components

  • Auction Service: Manage auction lifecycle and state
  • Bidding Engine: Handle bid validation and processing
  • Real-time Service: Broadcast updates via WebSocket
  • Bid Validator: Validate bids for amount, timing, and eligibility
  • Database: Persistent storage for auctions and bids
  • Message Queue: Decouple bid processing from updates

Mapping Core Functional Requirements to Components

Functional RequirementResponsible ComponentsKey Considerations
Real-time BiddingBidding Engine, Real-time ServiceLow latency, bid validation
Bid ValidationBid Validator, Auction ServiceAmount validation, timing checks
Auction ManagementAuction Service, DatabaseState management, lifecycle handling
Real-time UpdatesReal-time Service, Message QueueWebSocket connections, update broadcasting

Detailed Design

Bidding Engine

Purpose: Handle bid validation, processing, and auction state updates.

Key Design Decisions:

  • Bid Validation: Validate bid amount, timing, and user eligibility
  • Atomic Operations: Ensure bid processing is atomic
  • State Management: Maintain consistent auction state
  • Concurrency Control: Handle concurrent bids safely

Algorithm: Bid processing with validation

1. Receive bid request with amount and user_id
2. Validate bid:
   - Check auction is active
   - Check bid amount > current bid
   - Check user eligibility
   - Check timing (before auction end)
3. If valid:
   - Update auction state atomically
   - Store bid in database
   - Broadcast update to all participants
4. If invalid:
   - Return error with reason
5. Handle auction end conditions

Real-time Service

Purpose: Broadcast auction updates to all participants in real-time.

Key Design Decisions:

  • WebSocket Connections: Maintain persistent connections for real-time updates
  • Message Broadcasting: Broadcast updates to all connected users
  • Connection Management: Handle connection drops and reconnections
  • Update Filtering: Send relevant updates to each user

Algorithm: Real-time update broadcasting

1. User connects to auction via WebSocket
2. Send current auction state to user
3. When bid is placed:
   - Validate bid
   - Update auction state
   - Broadcast update to all connected users
4. Handle connection drops gracefully
5. Reconnect users with missed updates
6. Send auction end notifications

Bid Validator

Purpose: Validate bids for amount, timing, and user eligibility.

Key Design Decisions:

  • Amount Validation: Ensure bid amount exceeds current bid
  • Timing Validation: Ensure bid is placed before auction end
  • User Validation: Check user eligibility and bid limits
  • Fraud Detection: Detect suspicious bidding patterns

Algorithm: Bid validation

1. Check auction status (active, not ended)
2. Validate bid amount:
   - Must be > current highest bid
   - Must be >= minimum increment
3. Validate timing:
   - Must be before auction end time
   - Account for network latency
4. Validate user:
   - Check user exists and is active
   - Check user bid limit
   - Check for suspicious patterns
5. Return validation result

Auction Service

Purpose: Manage auction lifecycle and state transitions.

Key Design Decisions:

  • State Management: Track auction states (pending, active, ended)
  • Time Management: Handle auction start and end times
  • Winner Determination: Determine auction winner
  • State Transitions: Handle state changes atomically

Algorithm: Auction state management

1. Create auction with initial state "pending"
2. At start time:
   - Change state to "active"
   - Start accepting bids
   - Begin real-time updates
3. During auction:
   - Process incoming bids
   - Update current bid and bidder
   - Broadcast state changes
4. At end time:
   - Change state to "ended"
   - Determine winner
   - Send final notifications
5. Handle early termination if needed

Database Design

Auctions Table

FieldTypeDescription
auction_idVARCHAR(36)Primary key
item_nameVARCHAR(255)Auction item name
start_timeTIMESTAMPAuction start time
end_timeTIMESTAMPAuction end time
statusVARCHAR(50)Auction status
starting_priceDECIMAL(10,2)Starting price
current_bidDECIMAL(10,2)Current highest bid
winner_idVARCHAR(36)Auction winner

Indexes:

  • idx_status on (status) - Active auctions
  • idx_end_time on (end_time) - Auction scheduling

Bids Table

FieldTypeDescription
bid_idVARCHAR(36)Primary key
auction_idVARCHAR(36)Associated auction
user_idVARCHAR(36)Bidder
amountDECIMAL(10,2)Bid amount
timestampTIMESTAMPBid timestamp

Indexes:

  • idx_auction_timestamp on (auction_id, timestamp) - Auction bid history
  • idx_user_id on (user_id) - User bid history

Auction States Table

FieldTypeDescription
auction_idVARCHAR(36)Primary key
current_bidDECIMAL(10,2)Current highest bid
bid_countINTTotal bid count
time_remainingINTTime remaining in seconds
last_updatedTIMESTAMPLast update timestamp

Indexes:

  • idx_time_remaining on (time_remaining) - Active auctions

Scalability Considerations

Horizontal Scaling

  • Bidding Engine: Scale horizontally with load balancers
  • Real-time Service: Scale WebSocket connections with load balancers
  • Auction Service: Use consistent hashing for auction partitioning
  • Database: Shard auctions by auction_id

Caching Strategy

  • Redis: Cache auction states and recent bids
  • Application Cache: Cache frequently accessed auction data
  • Database Cache: Cache auction and bid data

Performance Optimization

  • Connection Pooling: Efficient database connections
  • Batch Processing: Batch bid updates for efficiency
  • Async Processing: Non-blocking bid processing
  • Resource Monitoring: Monitor CPU, memory, and network usage

Monitoring and Observability

Key Metrics

  • Bid Latency: Average bid processing time
  • Concurrent Bidders: Number of active bidders per auction
  • Bid Success Rate: Percentage of successful bids
  • System Health: CPU, memory, and network usage

Alerting

  • High Latency: Alert when bid processing time exceeds threshold
  • Connection Drops: Alert when WebSocket connections drop frequently
  • Bid Failures: Alert when bid failure rate increases
  • System Errors: Alert on auction processing failures

Trade-offs and Considerations

Consistency vs. Availability

  • Choice: Strong consistency for auction state and bids
  • Reasoning: Auction integrity requires immediate consistency

Latency vs. Throughput

  • Choice: Optimize for latency with real-time processing
  • Reasoning: Real-time bidding requires immediate response

Accuracy vs. Performance

  • Choice: Use atomic operations for bid processing
  • Reasoning: Auction accuracy is more important than processing speed

Common Interview Questions

Q: How would you handle bid sniping?

A: Use bid extensions, proxy bidding, and time synchronization to prevent bid sniping.

Q: How do you ensure bid order consistency?

A: Use atomic operations, timestamps, and sequence numbers to ensure bid order consistency.

Q: How would you scale this system globally?

A: Deploy regional auction servers, use geo-distributed databases, and implement data replication strategies.

Q: How do you handle auction time synchronization?

A: Use synchronized clocks, time servers, and client-side time validation to ensure accurate timing.


Key Takeaways

  1. Real-time Processing: WebSocket connections and message broadcasting are essential for real-time bidding
  2. Bid Validation: Multiple validation layers ensure auction integrity and prevent fraud
  3. State Management: Atomic operations and state transitions maintain auction consistency
  4. Scalability: Horizontal scaling and partitioning are crucial for handling concurrent bidders
  5. Monitoring: Comprehensive monitoring ensures system reliability and performance