Volume 14 · Chapter 4 — Enterprise Software Architecture Case Study Encyclopedia

E-Commerce Scale Architecture

Goutham Mayaluri 7 min read .NETC#

4.1 Introduction

E-commerce is the classic “scale to millions of users” case study, with a twist: its workload is enormously read-heavy (browsing dwarfs buying) but its checkout path demands correctness (never oversell inventory, never double-charge). It also faces extreme spikes - flash sales, holidays - that stress every part of the system. The architecture must serve massive read traffic cheaply while keeping the transactional checkout correct, which makes it a perfect illustration of applying the right consistency model per concern.

4.2 Reference Architecture

flowchart TB
  U["Users"] --> CDN["CDN (static, catalog pages)"]
  CDN --> GW["API Gateway / BFF"]
  GW --> Cat["Catalog Service\n(read-optimized, cached)"]
  GW --> Search["Search Service\n(search engine index)"]
  GW --> Cart["Cart Service (Redis)"]
  GW --> Order["Order Service"]
  Order --> Inv["Inventory Service"]
  Order --> Pay["Payment Service"]
  Order -- "events" --> Fulfil["Fulfillment / Notifications"]

4.3 Serving Read-Heavy Traffic Cheaply

The catalog and search - the overwhelming majority of traffic - are served from caches, CDNs, and purpose-built read stores (a search engine for product search, a denormalized catalog read model), so the origin and databases are shielded. Product data changes relatively rarely, so aggressive caching with sensible invalidation is highly effective. This is where most of the scale is won: keep the read path off the transactional systems.

4.4 The Correct Checkout Path

Checkout is where correctness matters. The order flow reserves inventory, authorizes payment, and creates the order - a multi-step process across services that uses the saga pattern with compensation (release the reservation if payment fails) and idempotency (a resubmitted order does not double-charge). Inventory reservation must prevent overselling under concurrency, especially during flash sales - a classic consistency challenge.

sequenceDiagram
  autonumber
  participant C as Checkout
  participant Inv as Inventory
  participant Pay as Payment
  participant Ord as Order
  C->>Inv: reserve items
  Inv-->>C: reserved
  C->>Pay: authorize
  alt payment ok
      Pay-->>C: approved
      C->>Ord: create order (confirmed)
  else payment fails
      Pay--xC: declined
      C->>Inv: compensate (release reservation)
  end

4.5 Search, Recommendations, and Spikes

Search uses a dedicated engine (indexing, filtering, ranking, increasingly semantic search via embeddings). Recommendations use ML over user behavior, served from precomputed models. Spikes are handled with autoscaling, aggressive caching, queue-based load leveling for checkout, and graceful degradation (shedding non-essential features under extreme load) so the core buying path survives a flash sale.

Principal Architect Interview Question

How would you design an e-commerce platform for millions of users and flash-sale spikes?

I design around two facts: the workload is overwhelmingly read-heavy (browsing and search dwarf buying), and the checkout path must be correct (never oversell, never double-charge), so I apply the right consistency model and scaling strategy per concern. For the read-heavy majority - catalog and search - I push traffic off the origin and databases: serve static and catalog content from a CDN, cache aggressively (product data changes rarely, so caching with sensible invalidation is very effective), and use purpose-built read stores - a denormalized catalog read model and a dedicated search engine for filtering, ranking, and increasingly semantic search. This is where most of the scale is won, because keeping reads off the transactional systems lets a modest backend serve enormous browse traffic. For checkout, where correctness matters, I use a saga across inventory, payment, and order services with compensation (release the inventory reservation if payment fails) and idempotency (a resubmitted or retried order never double-charges), and I design inventory reservation to prevent overselling under high concurrency - the classic flash-sale consistency challenge - using atomic reservation with appropriate consistency on the inventory store. Services are stateless and autoscale horizontally, with cart state in Redis. For flash-sale spikes specifically, I combine autoscaling with heavy caching, queue-based load leveling on the checkout path so bursts are absorbed rather than overwhelming the system, rate limiting to shed excess gracefully, and graceful degradation - shedding non-essential features (recommendations, rich personalization) under extreme load so the core buy path survives. I offload non-critical work (notifications, fulfillment, analytics) to async event-driven processing to keep the synchronous path fast. And I validate at target scale with load tests, watching p99, and design for failure with resilience patterns. The architectural through-line I’d emphasize is matching each concern to its needs: massively scalable, cheap, eventually-consistent reads for browsing and search, and correct, idempotent, saga-orchestrated transactional processing for checkout, with spike-handling (caching, autoscaling, load leveling, degradation) so the platform stays up and correct when traffic explodes.

Principal Architect Interview Question

How do you prevent overselling inventory during a high-concurrency flash sale?

Overselling happens when many concurrent checkouts each see stock available and all proceed, so the fix is to make inventory reservation atomic and correctly serialized on the item, so the “check and decrement” cannot race. Concretely, I reserve inventory with an atomic operation that both checks availability and decrements in one step - for example a conditional atomic decrement in the inventory store (a database row update guarded by a “quantity >= requested” condition, or an atomic operation in a fast store like Redis) - so that only as many reservations succeed as there is real stock, and the rest are rejected cleanly. This makes the inventory count for a hot item a strongly consistent, atomically-updated value, which is exactly the place I choose consistency over raw availability because overselling is a correctness failure with real business and customer consequences. Reservations are held with a timeout so abandoned carts release stock, and the reservation is part of the checkout saga - if payment fails, a compensating action releases it. To handle the extreme concurrency of a flash sale without the inventory store becoming a bottleneck or hotspot, I can partition or shard by product, keep the hot item’s count in a fast atomic store, and use queue-based load leveling so checkout requests for a scarce item are processed in a controlled manner rather than all hammering the store simultaneously - some designs even pre-allocate stock into a queue of “tickets.” I make the reservation operation idempotent (keyed by cart/order) so retries don’t double-reserve. The essential principle is that the availability check and the decrement must be a single atomic, serialized operation on the item so concurrent buyers cannot all succeed against the same units - I deliberately use strong consistency on inventory counts, accept the coordination cost, and mitigate the hotspot with partitioning and load leveling, because overselling is precisely the kind of correctness violation that eventual consistency cannot be allowed to cause. In an interview I’d frame it as choosing strong, atomic consistency for the scarce resource and engineering around the resulting hotspot, rather than letting the read-optimized, eventually-consistent parts of the system leak into the inventory decision.

4.6 Case Study Outcome

The e-commerce platform serves its read-heavy browse and search traffic from CDNs, caches, a denormalized catalog read model, and a search engine, keeping the transactional systems shielded. Checkout runs as an idempotent saga across inventory, payment, and order services with compensation, and inventory reservation is atomic to prevent overselling. Flash-sale spikes are absorbed with autoscaling, aggressive caching, queue-based load leveling, and graceful degradation of non-essential features. Each concern gets the consistency and scaling it needs - cheap eventual consistency for browsing, strong atomic consistency for inventory and payment.

Chapter Revision Notes

  • E-commerce is read-heavy browsing plus a correctness-critical checkout - apply consistency per concern.
  • Serve catalog/search from CDN, caches, and purpose-built read stores to win most of the scale.
  • Checkout is an idempotent saga across inventory, payment, and order with compensation.
  • Prevent overselling with atomic, serialized inventory reservation - strong consistency on the scarce resource.
  • Handle spikes with autoscaling, caching, queue-based load leveling, and graceful degradation.