🛒 Design E-Commerce Platform — System Design Interview Guide

Hard · Transactions & Inventory

Design an e-commerce platform like Amazon that handles product catalog, inventory management, shopping cart, checkout, and order fulfillment at massive scale.

Open the interactive E-Commerce Platform design on PrepGrind → Drag load balancers, caches, databases, and queues onto a canvas, run a live traffic simulation to watch latency and bottlenecks under load, and follow the full interview walkthrough below — free, in your browser.

Functional requirements

Non-functional requirements & scale

Capacity estimation

Normal: 115 orders/sec. Flash sale: ~1M/sec on hot items. Inventory decrement must be atomic to prevent overselling. Cart = session-like data (Redis). Orders = ACID transactions. Catalog = read-heavy (cached), inventory = write-heavy during sales.

Core entities

API design

High-level design

Browse: Elasticsearch for search, Redis cache for product details. Cart: Redis hash keyed by userId. Checkout: atomic inventory reservation (DB transaction / Redis DECR), then async order processing via Kafka.

Deep dives

🔒 Preventing Overselling

Naive: UPDATE inventory SET qty = qty - 1 WHERE qty > 0. Works but creates DB hotspot on flash sales. Better: Redis DECR for in-memory atomic counter (100K ops/sec per key). DB as source of truth, Redis as rate limiter. Pre-check Redis; if positive, proceed to DB transaction. Optimistic locking: include version in UPDATE WHERE clause.

🛍️ Flash Sale Architecture

Separate flash-sale service. Pre-allocate inventory tokens in Redis (SET token:productId count). Each purchase: atomically DECR. If result >= 0: proceed; else: reject immediately. Use rate limiter at gateway to shed load before reaching services. Queue overflow requests; process async with estimated wait time.

💳 Payment Idempotency

Network timeouts cause double-payment risk. Solution: client generates idempotencyKey (UUID). Payment service: INSERT INTO payments (idempotencyKey, ...) ON CONFLICT DO NOTHING; then check result. If payment already exists, return existing result. Store idempotency keys in Redis for 24h for fast lookup.

🔍 Product Search

Elasticsearch for full-text + filter search. Index: productId, name, description, categoryPath, price, rating, inStock. Faceted search: aggregations for filters. Cache frequent queries in Redis (TTL 5min). Write-through cache invalidation on product update. Use async indexing via Kafka — DB is source of truth.

Scaling considerations

What interviewers expect by level

Practice more system design case studies

PrepGrind runs entirely in your browser, free, no installation required. Loading the interactive playground…