Practice/Uber/Design an e-commerce platform
Design an e-commerce platform
System DesignMust
Problem Statement
Design an eBay-like e-commerce platform that allows users to view products, manage shopping carts, place orders, complete checkout, and process purchases. The system handles high read traffic on catalog and search, bursts of write traffic during promotions, and strict correctness for inventory and payments.
An e-commerce marketplace connects buyers with a large product catalog from multiple sellers. Buyers browse, compare offers, add items to a cart, check out with shipping and payment, and track orders. The core engineering challenges are handling inventory contention under concurrent purchases, multi-step checkout workflows that span payment and shipping services, and read scaling for the product catalog and search.
Interviewers at Uber ask this to see whether you can define clean APIs and data models that balance usability, scalability, and strong consistency where it matters. They probe how you handle inventory contention, multi-step checkout, idempotency, and read scaling for search and product detail.
Key Requirements
Functional
- Product discovery -- users search, filter, and view products with full-text search, facets, and product detail pages
- Shopping cart -- users add, update, and remove items with accurate pricing and real-time availability
- Checkout and payment -- users place orders via checkout including shipping address, taxes, and payment authorization
- Order management -- users view order status and history including shipments, cancellations, and returns
Non-Functional
- Scalability -- support millions of daily active users with read-heavy catalog browsing and write spikes during flash sales
- Reliability -- zero overselling; every successful checkout results in a fulfilled order; 99.9% availability for browse operations
- Latency -- product search under 200 ms; checkout completion under 3 seconds
- Consistency -- strong consistency for inventory and payments; eventual consistency acceptable for catalog search and product recommendations
What Interviewers Focus On
Based on real interview experiences at Uber and Meta, these are the areas interviewers probe most deeply:
1. Inventory Contention and Overselling Prevention
When many buyers race for limited stock, naive counter decrements lead to overselling. Interviewers expect explicit concurrency control.
Hints to consider:
- Use optimistic concurrency control with version numbers: read current stock, attempt update with version check, retry on conflict
- Implement inventory reservations: when a user adds to cart or starts checkout, temporarily reserve the item with a TTL
- Release reservations if checkout is not completed within the timeout
- For flash sales with extreme contention, consider a queue-based approach where purchase requests are serialized per SKU
2. Multi-Step Checkout Workflow (Saga Pattern)
Checkout spans tax calculation, shipping rate lookup, payment authorization, inventory confirmation, and order creation. Each step can fail independently.
Hints to consider:
- Model checkout as a saga with compensating actions: if payment fails, release inventory reservation; if shipping fails, void payment authorization
- Use a durable workflow engine to track progress and enable resume after crashes
- Make each step idempotent with unique order-level idempotency keys
- Handle partial failures gracefully: if payment is authorized but inventory runs out, void the authorization and notify the user
3. Catalog Search and Read Scaling
Product catalog browsing is the highest-traffic operation. Running full-text queries against the primary database will fail at scale.
Hints to consider:
- Use Elasticsearch for product search with full-text, faceted, and geospatial capabilities
- Propagate catalog updates from the primary database to Elasticsearch via change-data-capture (CDC) or Kafka events
- Cache product detail pages and search results in Redis with short TTLs
- Implement read replicas for the product database to serve product detail queries without impacting write throughput
4. Cart Management and Session Handling
Carts are ephemeral but must persist across sessions and devices. Interviewers look for a practical storage approach.
Hints to consider:
- Store cart state in Redis for fast access with a fallback to a durable store for cross-session persistence
- Validate cart item availability and pricing at checkout time, not just when items are added
- Handle price changes between add-to-cart and checkout: show the user the current price, not the stale cached price
- Support guest carts that merge with user accounts on login