Skip to content
ADevGuide Logo ADevGuide
Go back

System Design Interview: Design an E-Commerce Platform

By Pratik Bhuite | 35 min read

Hub: System Design / Interview Questions

Series: System Design Interview Series

Last verified: Sep 19, 2026

Part 1 of 24 in the System Design Interview Series

Key Takeaways

On this page
Reading Comfort:

System Design Interview: Design an E-Commerce Platform

An e-commerce platform looks like a set of familiar screens: search, product detail, cart, checkout, and order tracking. In a system design interview, the difficult part is not drawing those boxes. It is preserving inventory and payment correctness while browse traffic spikes, dependencies time out, and customers retry the same request.

This guide designs the platform around those invariants. It complements the narrower e-commerce checkout system design and links the decisions back to the reusable system design interview cheatsheet, the System Design hub, and Backend Interview Mastery.

Table of Contents

Open Table of Contents

Interview Framework: How to Approach This Problem

In a system design interview, spend the first five minutes making “e-commerce platform” concrete. Spend two minutes stating scale and correctness assumptions, ten minutes on the high-level flow, twenty minutes on inventory, ordering, and payment, and the final ten minutes on scale, security, and recovery.

Think aloud as you move between requirements and design. When you add a cache, say which read it protects. When you add a queue, say which user-visible operation can become eventual. When you choose a consistency model, name the business invariant it protects. That communication is more valuable than listing every cloud service you remember.

Step 1: Clarifying Requirements

Questions to Ask the Interviewer

Q: Is this a single-merchant store or a marketplace?

Assume a multi-merchant marketplace for the interview. A single merchant can remove seller isolation and split-order complexity, but the core catalog, cart, inventory, and order decisions remain.

Q: Which customer journeys are in scope?

Support browsing, search, product details, cart updates, checkout, payment authorization, order tracking, and cancellation. Leave recommendations, seller analytics, and international tax rules as follow-up scope.

Q: Do we need exact inventory or can stock be eventually consistent?

Product-listing stock badges may be stale by a few seconds. The reservation decision during checkout must be authoritative, because showing “one left” is a user-experience issue but overselling is a financial and fulfillment issue.

Q: Are prices calculated at read time or at checkout?

Display prices can come from a cache, but checkout must snapshot the price, currency, promotions, and tax inputs before payment. The order must retain that snapshot for later support and refunds.

Q: What scale and geography should we target?

Assume a global marketplace with 50 million registered users, 5 million daily active users, and a seasonal peak that is ten times the normal traffic.

Q: Which latency and availability targets matter?

Target p95 under 200 ms for cached browse reads, p95 under 500 ms for cart writes, 99.99% availability for browsing, and 99.9% for checkout orchestration. No accepted order may be silently lost.

Functional Requirements

  1. Merchants can create and update products, prices, and availability.
  2. Buyers can browse categories, search products, and view product details.
  3. Buyers can add, remove, and update quantities in a cart across devices.
  4. The platform can reserve inventory and release expired reservations.
  5. Buyers can submit an order and authorize a payment with an idempotency key.
  6. Buyers can view order status, shipment updates, and cancellation eligibility.
  7. Fulfillment and notification services receive durable order events.

Non-Functional Requirements

  1. Correctness: inventory cannot be committed twice for the same unit; payment and order state are auditable.
  2. Latency: cached catalog reads should stay below 200 ms at p95; checkout can acknowledge PENDING rather than blocking on fulfillment.
  3. Availability: browse traffic should degrade gracefully if recommendations or reviews are unavailable.
  4. Scalability: read-heavy catalog traffic and write-heavy order traffic scale independently.
  5. Durability: an accepted order and its payment intent survive an instance, zone, or worker failure.
  6. Security: customer, seller, and operator data are isolated and sensitive payment data never enters application logs.

Step 2: Core Assumptions and Constraints

Use round numbers so the interviewer can change them without forcing a redesign:

  • 50 million registered buyers and 5 million daily active buyers.
  • 100 million catalog SKUs, with a small fraction accounting for most reads.
  • 100,000 product-read requests per second at a holiday peak.
  • 5,000 cart writes per second and 1,000 checkout attempts per second at peak.
  • A reservation lasts 10 minutes unless payment and order creation complete sooner.
  • A cart is user-owned, but its price and inventory are revalidated during checkout.
  • Search indexes and catalog projections may lag the source of truth by seconds.
  • Orders, payment intents, and reservations require transactional state transitions.

The key constraint is that not every part of the platform needs the same consistency. Search can be eventually consistent. An inventory decrement cannot be based on a stale search document. Separating those guarantees keeps the system both explainable and affordable.

Step 3: High-Level Architecture

“I’ll start with a platform-level architecture, then deep-dive into the inventory reservation boundary because that is where concurrency becomes a business risk.”

System Flow Diagram

flowchart TD
    A[Buyer or Merchant] --> B[CDN and WAF]
    B --> C[API Gateway]
    C --> D[Catalog and Search]
    C --> E[Cart Service]
    C --> F[Checkout and Order]
    F --> G[Inventory Service]
    F --> H[Payment Adapter]
    D --> I[(Catalog DB and Search Index)]
    E --> J[(Cart Store)]
    G --> K[(Inventory Ledger)]
    F --> L[(Order DB)]
    F --> M[Outbox]
    M --> N[Event Bus]
    N --> O[Fulfillment]
    N --> P[Notifications]
    N --> Q[Analytics]
    H --> R[Payment Provider]
    G -. expired hold .-> S[Reservation Reaper]

    classDef edge fill:#e3f2fd,stroke:#1565c0,stroke-width:2px,color:#000000;
    classDef service fill:#ede7f6,stroke:#4527a0,stroke-width:2px,color:#000000;
    classDef data fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px,color:#000000;
    classDef async fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000000;
    class A,B,C edge;
    class D,E,F,G,H,O,P,Q service;
    class I,J,K,L data;
    class M,N,S async;

Component Breakdown

  • CDN and WAF: serve static assets, absorb edge traffic, and block obvious abuse before it reaches the application.
  • API gateway: authenticates requests, applies quotas, routes by resource, and adds correlation IDs. The gateway does not own order state.
  • Catalog and search: publish product documents to a search index and keep authoritative merchant data in a catalog store.
  • Cart service: stores short-lived buyer intent and calculates a fresh checkout snapshot instead of treating a cart price as final.
  • Checkout and order service: owns the order state machine and idempotency boundary.
  • Inventory service: records reservations and releases in an authoritative ledger, partitioned by SKU or fulfillment location.
  • Event bus and workers: decouple fulfillment, notifications, analytics, and search indexing from the customer request.

Walking Through the Data Flow

  1. A buyer requests a product page. The CDN serves static assets and the gateway routes the API request.
  2. Catalog data comes from a cache or read-optimized projection; the search index supplies candidates, never the final stock decision.
  3. A cart write stores the buyer’s selected SKU and quantity. It does not reserve inventory indefinitely.
  4. Checkout validates the cart, snapshots price and tax inputs, and asks inventory to create short-lived holds.
  5. The payment adapter authorizes the amount with the provider’s idempotency key.
  6. A successful authorization commits the order and an outbox event in one local transaction.
  7. Consumers fulfill, notify, and index the order asynchronously. The order API exposes the current state and a correlation ID.
  8. A reaper releases expired holds; reconciliation compares provider, reservation, and order records after ambiguous failures.

This architecture isolates the hot read path from correctness-sensitive writes. It also lets the platform add a recommendation engine or a new shipping provider without making the checkout API wait for unrelated work.

Step 4: The Hardest Problem - preventing overselling under concurrency

Consider one SKU with two units remaining. Ten buyers read “2 available” at nearly the same time. If each request writes quantity = quantity - 1 after an unprotected read, more than two orders can appear successful. A cache lock alone is not enough: it can expire, be bypassed, or become a single point of failure.

Approach 1: Read, then decrement

The service reads stock, checks that it is positive, and writes a new value. This is simple, but two requests can pass the check before either write commits. Verdict: reject for the authoritative reservation path.

Approach 2: Global distributed lock

Acquire a Redis-style lock per SKU, decrement the database, and release the lock. This serializes hot keys, but correctness now depends on lease expiry, fencing, and lock recovery. It can be useful as load shedding, but it should not be the only invariant boundary. Verdict: supporting control, not the source of truth.

Approach 3: Conditional reservation transaction

Keep an inventory ledger and execute a conditional update such as “reserve only when available quantity is at least requested quantity.” Store a unique reservation ID, expiry time, and version in the same transaction. Verdict: chosen. The database constraint protects correctness even when workers retry or a cache is stale.

A simplified PostgreSQL transaction looks like this:

BEGIN;

UPDATE inventory_balance
SET available = available - :quantity,
    reserved = reserved + :quantity,
    version = version + 1
WHERE sku_id = :sku_id
  AND available >= :quantity;

-- The application checks that exactly one row changed.
-- Zero rows means the reservation cannot be granted.
INSERT INTO inventory_reservation
  (reservation_id, sku_id, order_id, quantity, expires_at, status)
VALUES
  (:reservation_id, :sku_id, :order_id, :quantity, :expires_at, 'HELD');

COMMIT;

The reservation API is idempotent on (order_id, reservation_id). A retry returns the original hold instead of subtracting stock again. When the hold expires, a reaper performs the inverse ledger transition with a compare-and-set on the reservation status, so it cannot release stock that has already been committed.

Step 5: API and Order State Design

The main technical decision is to separate a customer-facing command from its durable state. The API can acknowledge a valid request quickly while the state machine continues through payment, fulfillment, and notification.

Core APIs

GET  /v1/products/{productId}
GET  /v1/search?q=wireless+headphones&cursor=...
PUT  /v1/carts/{cartId}/items/{skuId}
POST /v1/checkout-sessions
POST /v1/orders
GET  /v1/orders/{orderId}
POST /v1/orders/{orderId}/cancel

POST /v1/orders requires an Idempotency-Key scoped to the authenticated buyer. The response can be immediate when the order is committed or return 202 Accepted with an order ID and PENDING_PAYMENT state when a provider response is still uncertain.

Order State Machine

flowchart TD
    A[CHECKOUT_CREATED] --> B[INVENTORY_HELD]
    B --> C[PAYMENT_AUTHORIZED]
    C --> D[ORDER_CONFIRMED]
    D --> E[FULFILLING]
    E --> F[SHIPPED]
    F --> G[DELIVERED]
    B --> H[HOLD_EXPIRED]
    C --> I[PAYMENT_FAILED]
    D --> J[CANCEL_REQUESTED]
    J --> K[REFUND_PENDING]
    K --> L[CANCELLED]
    C -. timeout .-> M[RECONCILIATION]
    M --> C

    classDef active fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px,color:#000000;
    classDef failure fill:#ffebee,stroke:#b71c1c,stroke-width:2px,color:#000000;
    classDef pending fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,color:#000000;
    class A,B,C,D,E,F,G active;
    class H,I,J,K,L failure;
    class M pending;

The order record stores the state transition version, not just a string status. A worker that reads version 4 cannot overwrite a record already at version 5. This optimistic concurrency check makes duplicate events safe and keeps out-of-order consumers from regressing an order.

Step 6: Database Design and Storage

Data Classification

Hot data includes product-page cache entries, cart sessions, inventory counters for popular SKUs, and active reservation leases. Use Redis or an equivalent cache for speed, but keep a durable source of truth behind it.

Warm data includes catalog records, orders, payment intents, seller settings, and recent shipment projections. A relational database is a strong default for orders, money, and state transitions because constraints and transactions express the business invariants directly.

Cold data includes product images, invoices, audit exports, and old event payloads. Object storage with lifecycle policies is cheaper and keeps large blobs out of transactional tables.

Core Relational Schema

CREATE TABLE orders (
  order_id UUID PRIMARY KEY,
  buyer_id UUID NOT NULL,
  currency CHAR(3) NOT NULL,
  total_minor_units BIGINT NOT NULL,
  state TEXT NOT NULL,
  state_version BIGINT NOT NULL DEFAULT 0,
  idempotency_key TEXT NOT NULL,
  created_at TIMESTAMPTZ NOT NULL,
  UNIQUE (buyer_id, idempotency_key)
);

CREATE TABLE inventory_reservations (
  reservation_id UUID PRIMARY KEY,
  order_id UUID NOT NULL,
  sku_id UUID NOT NULL,
  quantity INTEGER NOT NULL CHECK (quantity > 0),
  status TEXT NOT NULL,
  expires_at TIMESTAMPTZ NOT NULL,
  UNIQUE (order_id, sku_id)
);

The unique idempotency constraint protects retries. total_minor_units avoids floating-point money errors. state_version protects transitions, while expires_at lets a worker find abandoned holds efficiently.

Indexing and Storage Strategy

  • Index orders by (buyer_id, created_at DESC) for order history.
  • Index reservations by (status, expires_at) for the reaper.
  • Partition very large event and order-history tables by time or tenant after measuring query patterns.
  • Store search documents separately from the catalog source so reindexing cannot corrupt merchant data.
  • Replicate read-only product projections, but route inventory and order writes to their authoritative region.

Step 7: Scaling the System

Start by scaling the component that is actually hot. A catalog read does not need the same topology as an inventory write.

Cache immutable or versioned product documents at the CDN and application cache. Use a search index for text, filters, and ranking, then fetch authoritative price or availability when the user enters checkout. This protects the database during a browse spike without pretending search is a transaction.

Bottleneck 2: Hot Inventory SKUs

Partition inventory by SKU or fulfillment location, serialize updates for a single hot key, and queue excess attempts with a bounded admission policy. For flash sales, a token bucket at the edge can reject impossible demand before it consumes database connections. The flash-sale inventory scenario gives a focused version of this trade-off.

Bottleneck 3: Order and Payment Writes

Keep the order transaction short, use an outbox, and scale workers on queue age rather than CPU alone. If one worker commits 100 order commands per second, 1,000 peak commands need 10 workers; provision 20 for a two-times failure and burst margin. If each command causes four downstream events, the event bus must absorb roughly 4,000 event publications per second before retry amplification.

Bottleneck 4: Database Connections

Use a pool per application replica with a global connection budget. A hundred application replicas with 50 connections each can overload a database that only supports 2,000 active sessions. A pooler, bounded concurrency, and read replicas are safer than increasing every local pool.

Geographic Strategy

Serve catalog and media from regional edges. Route a buyer to a home region for cart and order writes, while asynchronously replicating read projections. If the interviewer requires multi-region inventory writes, explain the cost: either assign a single authority per SKU, accept a coordination quorum, or trade strict availability for reconciliation. Do not claim active-active correctness without naming that coordination boundary.

Step 8: Security and Permissions

Authentication identifies the buyer, seller, or operator. Authorization decides whether that principal can read a cart, change a listing, reserve stock, or refund an order. Enforce the decision in the service that owns the resource; the gateway’s coarse check is not enough.

Use seller-scoped roles such as CATALOG_EDITOR, INVENTORY_MANAGER, and ORDER_SUPPORT. Buyers can access only their own carts and orders. Support operators may view a payment status but should not see full card details or silently alter an order.

Protect the payment boundary by tokenizing payment methods with the provider, encrypting sensitive data, and redacting request bodies in logs. Verify webhook signatures, reject replayed event IDs, and require a correlation ID for every state-changing operation. Apply rate limits by identity and IP, but avoid making a single shared NAT gateway look like one customer.

Step 9: Handling Edge Cases

1. Buyer retries after a timeout

The client repeats the same idempotency key. The order service returns the saved result or PENDING status; it does not create a second reservation or payment intent.

2. Payment succeeds but the response is lost

Persist the local payment intent before the provider call, then reconcile by provider reference. A webhook or scheduled reconciliation moves the state forward. Never mark an order failed solely because one synchronous response timed out.

3. Inventory hold expires during payment

The reservation commit uses a conditional status transition. If the reaper wins first, payment authorization is voided or refunded according to the provider contract. The user sees an explicit inventory-expired result instead of a false confirmation.

4. Search shows a product that was removed

The catalog publish pipeline uses versioned documents and tombstones. The product API checks the source of truth before allowing a cart or checkout operation, so stale search results cannot create an order.

5. Event consumer is down

The outbox retains unpublished events and the broker retains published events until acknowledgement. Consumers resume from their offsets, and a dead-letter queue captures poison messages for bounded replay. The order remains queryable even while fulfillment is delayed.

6. One merchant ships only part of a marketplace order

Represent an order as a customer-facing aggregate with merchant fulfillment groups beneath it. Each group has its own shipment state and compensation rules, while the aggregate exposes partial shipment and refund status.

Step 10: Performance Optimizations

1. Cache by read semantics

Cache category pages, product metadata, and search suggestions with versioned keys. Do not cache an inventory reservation decision for longer than the business can tolerate. A cache hit protects latency; it never replaces the conditional write.

2. Protect the tail, not only the average

Set deadlines for every downstream call, use bounded retries with jitter, and stop retrying when the request’s remaining budget is exhausted. Track p95 and p99 latency separately from the average because checkout pain usually appears in the tail first.

3. Precompute search and catalog projections

Publish catalog changes through an event stream and build denormalized search documents asynchronously. This makes browse reads cheap while keeping merchant writes focused on the authoritative model.

4. Reduce fan-out in checkout

Snapshot the cart, pricing, and tax inputs once per checkout session. Parallelize independent reads, but sequence the reservation and payment steps around the invariant. Fewer synchronous calls mean fewer timeout combinations to recover from.

5. Use backpressure and graceful degradation

When analytics or recommendations lag, keep browsing and ordering available without waiting for them. When inventory is saturated, return a bounded “try again” response rather than allowing unbounded queues to consume all database connections.

Real-World Implementations

Amazon-style marketplaces separate catalog discovery from order and fulfillment correctness because the workloads and consistency needs differ. Shopify-style commerce platforms also expose a broad set of merchant, catalog, inventory, checkout, and fulfillment capabilities behind stable APIs. The implementation details vary, but the interview-level pattern is consistent: use projections for discovery, transactional boundaries for money and stock, and events for work that can finish later.

The most useful production lesson is not a particular vendor. It is the explicit boundary between “the customer can browse this information” and “the platform has committed this business fact.” That boundary makes incident recovery and reconciliation possible.

Common Interview Follow-Up Questions

1. Why not put everything in one database transaction?

A transaction spanning the inventory database, payment provider, search index, and shipping system would be slow, brittle, and usually impossible to coordinate with external providers. Keep the local order and reservation transition atomic, then use idempotent commands, an outbox, and compensating actions across service boundaries. The trade-off is eventual completion, but the state machine makes that uncertainty visible.

2. How would you support a flash sale?

Pre-warm catalog caches, rate-limit at the edge, partition hot SKUs, and admit only as many reservation attempts as the inventory authority can process. A short-lived queue can absorb a controlled burst, but an unbounded queue only hides overload. Explain what the buyer sees when the queue is full and how abandoned holds are released.

3. What if a seller changes a price while a buyer is checking out?

The checkout service creates a price snapshot with a version and timestamp. If the price changed after the cart was created, the API either honors an explicit policy or asks the buyer to confirm the new total. The order stores the final snapshot so later refunds and support do not depend on today’s catalog price.

4. How do you prevent duplicate payment charges?

Create one payment intent per order and send a stable provider idempotency key on every retry. Store the provider reference and status locally, verify signed webhooks, and reconcile ambiguous states. The payment system design covers this boundary in greater depth.

5. How do you keep search results fresh?

Catalog writes publish versioned change events. Indexers consume them idempotently and ignore an event older than the document version already indexed. A freshness metric and replayable topic make a delayed index visible and recoverable instead of silently stale.

6. How would you make order history highly available?

Keep the authoritative write model in a durable primary and maintain a read projection that can be replicated across regions. A buyer may briefly see a stale status after a failover, but the API should label uncertainty and converge from the event log. Strong consistency is reserved for the operations that can change money or fulfillment.

Conclusion

  1. Begin with buyer and merchant workflows, then quantify the traffic and correctness targets.
  2. Keep catalog and search fast with projections, but never use them as the inventory authority.
  3. Protect stock with conditional reservations, unique keys, expiry, and versioned transitions.
  4. Make orders and payments idempotent so retries converge on one auditable result.
  5. Use outbox events, queues, and reconciliation to make fulfillment recoverable after partial failure.
  6. Scale each workload independently and explain what happens when a dependency is slow or unavailable.

The next topic in this series covers designing a payment system in isolation. For a prerequisite, revisit idempotency in REST APIs and compare its request boundary with the order state machine above.

References

  1. Amazon Builders’ Library - Making retries safe - https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/
  2. Stripe - Idempotent requests - https://docs.stripe.com/api/idempotent_requests
  3. Apache Kafka - Introduction - https://kafka.apache.org/intro
  4. Google SRE - Handling overload - https://sre.google/sre-book/handling-overload/

YouTube Videos

  1. “Senior System Design Mock Interview: Design an e-commerce platform” - https://www.youtube.com/watch?v=RuGY_1pap74
  2. “Design Amazon’s E-Commerce Platform: The System Design Interview Walkthrough” - https://www.youtube.com/watch?v=YHjH1VfUU6Q

Share this post on:

Next in Series

Continue through the [object Object] with the next recommended article.

Related Posts

Keep Learning with New Posts

Subscribe through RSS and follow the project to get new series updates.

Was this guide helpful?

Share detailed feedback

Previous Post
How a Modern Backend Application Works End to End
Next Post
Consistency Models: Strong, Eventual and Read-Your-Writes