Amazon-like E-commerce Platform
End-to-end architecture for a large B2C e-commerce platform with catalog, search, cart, checkout, payments, inventory, orders and recommendations, built to survive 10× sale-day peaks.
[!ASSUMPTION] Scope of this design A hypothetical retailer "ShopScale" selling first-party and marketplace items in several countries. Numbers are planning assumptions for interview use, not figures from any real company.
1. Business problem and objectives
ShopScale's legacy monolith cannot handle festive-sale peaks (checkout errors above 5% at peak), releases take six weeks, and international expansion requires multi-currency and data residency. Objectives:
- Checkout success rate ≥ 99.9% during peaks of 10× normal traffic.
- Product page p95 server latency < 200 ms worldwide.
- Weekly (later daily) independent releases per domain team.
- Launch two new countries per year with local payment methods.
- Reduce infrastructure cost per order by 25%.
2. Business model and revenue generation
| Stream | Description | Architecture implication |
|---|---|---|
| First-party retail margin | Buy inventory, sell at markup | Inventory and pricing accuracy are critical |
| Marketplace commission | 8–20% per third-party sale | Seller onboarding, split payments, settlements, ledger |
| Subscription (Prime-like) | Free fast delivery, benefits | Entitlements service, recurring billing |
| Advertising | Sponsored products in search and pages | Ad auction, low-latency ad serving, attribution |
| Fulfilment services | Warehouse/logistics for sellers | WMS integration, fee calculation |
3. Functional requirements
- Browse categories and product detail pages with images, variants, reviews.
- Search with filters, facets, autocomplete, typo tolerance.
- Cart (guest and signed-in), wishlists, saved addresses.
- Checkout: delivery options, promotions, taxes, multiple payment methods.
- Orders: status tracking, cancellation, returns and refunds.
- Inventory: per-warehouse stock, reservations, available-to-promise.
- Seller portal: listings, pricing, stock, orders, payouts.
- Recommendations and personalized home page.
- Notifications: email, SMS, push.
- Admin: catalog moderation, promotions, customer service tools.
Out of scope for v1: live video shopping, B2B procurement.
4. Non-functional requirements
| Attribute | Target |
|---|---|
| Availability | Checkout and payment 99.95% monthly; browse 99.9% |
| Latency | Product page API p95 < 200 ms, search p95 < 300 ms, checkout submit p95 < 1.5 s (incl. payment) |
| Peak | 10× normal traffic for 4 hours during sales |
| Consistency | No overselling of limited stock; no double charges; prices shown = prices charged |
| Durability | RPO 0 for orders and payments within region; RPO ≤ 1 min cross-region |
| RTO | 15 minutes for checkout |
| Security/compliance | PCI DSS (minimized scope), GDPR/DPDP privacy, SOC 2 |
| Data residency | EU customer PII stored in EU |
5. Expected user base and traffic assumptions
| Metric | Normal | Peak (sale) |
|---|---|---|
| Daily active users | 20 M | 60 M |
| Page/API requests | ~25K RPS | ~250K RPS |
| Search queries | 3K RPS | 30K RPS |
| Orders | 2M/day (~25/s avg) | 1,000 orders/s for the first hour |
| Catalog size | 200 M SKUs (incl. marketplace) | – |
| Product images | 1.5 B images, ~400 TB | CDN egress peaks ~200 Gbps |
Derived conclusions: browse traffic must be absorbed by CDN and caches; order writes (1,000/s) fit a well-sized relational primary per region but inventory hot SKUs need special handling; search needs a horizontally scaled cluster.
6. High-level architecture
- Edge: CDN for static assets, images and cacheable HTML; WAF and bot management; virtual waiting room for sale launches.
- Experience layer: Next.js web app with server-side rendering, native mobile apps, and BFFs per channel.
- Domain microservices (owned by stream-aligned teams): Catalog, Search, Pricing, Promotions, Cart, Checkout, Payment, Inventory, Order, Fulfilment, Returns, Customer, Seller, Notification, Recommendation.
- Integration: Kafka for domain events; transactional outbox per service; Step Functions/Temporal for checkout and return sagas.
- Data: per-service databases (Aurora PostgreSQL, DynamoDB), OpenSearch, Redis, S3 data lake with Iceberg tables.
- Platform: EKS, GitOps, observability, secrets, feature flags.
7. Detailed component architecture
| Component | Responsibility | Key design choice | Why |
|---|---|---|---|
| Catalog | Product, variant, attribute, media metadata | DynamoDB with item collections per product; S3 + CDN for media | Read-heavy, key-based, 200M items |
| Search | Query, facets, ranking, autocomplete | OpenSearch fed by CDC; learning-to-rank with click data | Full-text relevance not possible in OLTP DB |
| Pricing | Base prices, price books per country/segment | Aurora + Redis cache; versioned price books | Auditability of price changes |
| Promotions | Coupons, bundles, stacked offers | Rules compiled to an in-memory evaluator per region | Must evaluate in < 30 ms |
| Cart | Line items, guest merge | DynamoDB keyed by cart ID, TTL 30 days | High write rate, simple access |
| Checkout | Orchestrates quote → order → payment → confirm | Temporal/Step Functions saga; idempotent steps | Long-running, failure-prone flow |
| Payment | Payment intents, PSP integration, refunds | Aurora + ledger tables; PSP tokens only | PCI scope reduction, correctness |
| Inventory | Stock per node, reservations | Aurora with conditional updates; Redis counters for hot SKUs | No oversell, high contention SKUs |
| Order | Order lifecycle state machine | Aurora; outbox events | ACID across order + lines |
| Fulfilment | Allocation to warehouses, shipments | Event-driven; integrates WMS/carriers | Asynchronous by nature |
| Recommendation | Candidates + ranking | Feature store + ANN index; SageMaker/Vertex endpoints | ML lifecycle separate from OLTP |
| Notification | Templates, channels, preferences | SQS-driven workers; SES/SNS/FCM | Isolates slow providers |
8. Architecture diagram
flowchart TB
subgraph Clients
WEB[Web: Next.js SSR]
APP[Mobile apps]
SELL[Seller portal]
end
subgraph Edge
CDN[CDN + WAF + bot mgmt]
WR[Virtual waiting room]
end
subgraph Experience
GW[API gateway]
BFFW[Web BFF]
BFFM[Mobile BFF]
end
subgraph Domain services on EKS
CAT[Catalog]
SRCH[Search]
PRC[Pricing]
PROMO[Promotions]
CART[Cart]
CHK[Checkout orchestrator]
PAY[Payment]
INV[Inventory]
ORD[Order]
FUL[Fulfilment]
REC[Recommendations]
NOTIF[Notification]
end
subgraph Data
DDB[(DynamoDB: catalog, cart)]
AUR[(Aurora PostgreSQL: orders, payments, inventory, pricing)]
OS[(OpenSearch)]
RED[(Redis)]
S3[(S3 media + data lake)]
end
K[[Kafka: domain events]]
PSP[Payment service providers]
WMS[Warehouses and carriers]
WEB & APP --> CDN --> WR --> GW
SELL --> GW
GW --> BFFW & BFFM
BFFW & BFFM --> CAT & SRCH & PRC & CART & CHK & REC
CHK --> PROMO & INV & PAY & ORD
PAY --> PSP
CAT --> DDB
CART --> DDB
ORD & PAY & INV & PRC --> AUR
SRCH --> OS
CAT & PRC & INV --> RED
ORD & PAY & INV & CAT -- outbox --> K
K --> SRCH & FUL & NOTIF & REC
K --> S3
FUL --> WMS
CDN --> S39. Frontend architecture
- Web: Next.js (React) with server-side rendering and incremental static regeneration for product and category pages (SEO and fast first paint); client components for cart and personalization; edge middleware for geo/currency.
- Micro-frontends only where teams truly need independent deployment (e.g. checkout vs browse) using module federation or route-level splits; otherwise one repo with clear ownership.
- Mobile: native (Swift/Kotlin) or React Native; shared design system; server-driven UI for home page layouts to avoid app releases for merchandising changes.
- Performance budget: LCP < 2.5 s on mid-range mobile, JS < 200 KB on product pages, images via responsive
srcsetand AVIF/WebP from an image CDN. - Resilience: personalized blocks load asynchronously; if recommendations fail, the page still renders.
10. Backend architecture
- Java 21/25 with Spring Boot 3.x/4.x for core transactional services (team skills, ecosystem), virtual threads for I/O-bound services; Go or Node for some edge/BFF services if teams prefer.
- Hexagonal architecture inside services: domain logic isolated from adapters (REST, Kafka, DB).
- Each service owns its data; no shared database. Cross-service reads use APIs or replicated read models.
- Synchronous calls only on the request path that needs an immediate answer (price, stock check, payment authorization); everything else via events.
- Idempotency keys on all mutating APIs; transactional outbox for events.
11. API design with sample REST endpoints
GET /v1/products/{productId}?locale=en-IN¤cy=INR
GET /v1/search?q=running+shoes&brand=acme&size=9&sort=relevance&page[cursor]=...
POST /v1/carts -> { cartId }
POST /v1/carts/{cartId}/items { sku, quantity }
POST /v1/checkout/quotes { cartId, addressId, deliveryOption, couponCodes[] }
POST /v1/orders Idempotency-Key: 7f3c... { quoteId, paymentMethodToken }
GET /v1/orders/{orderId}
POST /v1/orders/{orderId}/cancellations
POST /v1/orders/{orderId}/returns { lines[{ orderLineId, qty, reason }] }Example order creation response:
{
"orderId": "ord_01JD7Q9X3K",
"status": "PAYMENT_PENDING",
"total": { "amount": "2499.00", "currency": "INR" },
"paymentAction": { "type": "REDIRECT_3DS", "url": "https://psp.example/3ds/..." },
"links": { "self": "/v1/orders/ord_01JD7Q9X3K" }
}Design notes: cursor-based pagination; money as decimal strings with currency; quoteId locks price and promotions for 15 minutes so the price shown equals the price charged; 202/async status for long operations; versioned paths for public APIs.
12. Database schema and data model
Order service (Aurora PostgreSQL):
CREATE TABLE orders (
order_id text PRIMARY KEY,
customer_id text NOT NULL,
status text NOT NULL CHECK (status IN ('PAYMENT_PENDING','CONFIRMED','PARTIALLY_SHIPPED','SHIPPED','DELIVERED','CANCELLED','FAILED')),
currency char(3) NOT NULL,
total_amount numeric(14,2) NOT NULL,
quote_id text NOT NULL,
idempotency_key text NOT NULL UNIQUE,
created_at timestamptz NOT NULL DEFAULT now(),
version int NOT NULL DEFAULT 0
);
CREATE INDEX ON orders (customer_id, created_at DESC);
CREATE TABLE order_lines (
order_id text REFERENCES orders(order_id),
line_no int,
sku text NOT NULL,
seller_id text NOT NULL,
qty int NOT NULL CHECK (qty > 0),
unit_price numeric(14,2) NOT NULL,
PRIMARY KEY (order_id, line_no)
);
CREATE TABLE outbox (
id uuid PRIMARY KEY, aggregate_id text NOT NULL, event_type text NOT NULL,
payload jsonb NOT NULL, created_at timestamptz NOT NULL DEFAULT now()
);Inventory (per fulfilment node):
CREATE TABLE stock (
sku text, node_id text, on_hand int NOT NULL, reserved int NOT NULL DEFAULT 0,
PRIMARY KEY (sku, node_id), CHECK (reserved <= on_hand)
);
-- Reserve atomically; zero rows updated means insufficient stock
UPDATE stock SET reserved = reserved + :qty
WHERE sku = :sku AND node_id = :node AND on_hand - reserved >= :qty;Catalog (DynamoDB single-table): PK = PRODUCT#<id>, SK = META | VARIANT#<sku> | MEDIA#<n>; GSI on SELLER#<id> for seller listings.
13. Database technology selection and reasoning
| Data | Store | Reasoning | Alternative and when |
|---|---|---|---|
| Orders, payments, inventory, pricing | Aurora PostgreSQL | ACID, constraints, familiar SQL, read replicas, Global Database for DR | Spanner/Aurora DSQL if multi-region active writes are required |
| Catalog, cart | DynamoDB | Massive key-based scale, serverless, single-digit ms | MongoDB/Cosmos DB on other clouds |
| Search | OpenSearch | Full-text, facets, k-NN for semantic search | Algolia/Elastic Cloud to reduce ops; Vertex AI Search on GCP |
| Cache, sessions, hot counters | ElastiCache (Valkey) | Sub-ms latency, atomic ops | In-process Caffeine for tiny reference data |
| Analytics | S3 + Iceberg, Athena/Spark, Redshift for BI | Open format, cheap storage, many engines | BigQuery/Snowflake |
| Recommendations features | Feature store (SageMaker/Feast) + vector index | Consistent online/offline features | Managed Personalize for faster start |
14. Authentication and authorization
- Customers: OIDC via a CIAM (Cognito, Auth0, Entra External ID); short-lived access tokens (5–15 min), refresh token rotation, passkeys/MFA for account changes.
- Sellers and staff: workforce SSO (Entra ID/Okta) with MFA; RBAC + attribute checks (seller can only access own listings).
- Services: workload identity (IRSA/EKS Pod Identity), mTLS via mesh for east-west traffic.
- Authorization: gateway validates token and scopes; services enforce object-level checks (
order.customer_id == token.sub), mitigating BOLA (OWASP API1).
15. Security architecture
- PCI DSS scope reduction: card data entered in PSP-hosted fields/iframes; ShopScale stores only tokens. Payment service in a separate account/VPC with strict egress.
- WAF (OWASP rules, bot control, rate rules on login/checkout), DDoS protection.
- Encryption: TLS 1.2+ everywhere; KMS keys per data domain; field-level encryption for PII where needed.
- Secrets in Secrets Manager with rotation; no long-lived credentials.
- Supply chain: SBOMs, image signing, dependency scanning, admission policies.
- Fraud: risk scoring on checkout (device fingerprint, velocity, ML score) with step-up authentication.
- Privacy: PII inventory, data minimization, retention policies, DSAR automation, EU data in EU region.
16. Caching strategy
| What | Where | TTL / invalidation |
|---|---|---|
| Images, JS, CSS | CDN | Long TTL, content-hashed URLs |
| Product page HTML (non-personalized) | CDN / ISR | 60 s + stale-while-revalidate; purge on product update event |
| Product details | Redis | 10 min; invalidated by catalog CDC |
| Price and stock badges | Redis | 5–10 s TTL (freshness matters) |
| Search results for top queries | Redis | 60 s |
| Checkout totals | Never cached | Recomputed from quote |
Stampede protection with request coalescing; TTL jitter; local Caffeine cache for promotions rules.
17. Messaging and event-driven architecture
Core events: ProductUpdated, PriceChanged, StockChanged, OrderPlaced, PaymentAuthorized, PaymentFailed, OrderConfirmed, ShipmentCreated, OrderDelivered, ReturnRequested, RefundIssued.
- Kafka topics partitioned by aggregate ID (orderId, sku) for ordering.
- Avro schemas in a registry; backward-compatible evolution.
- Outbox + Debezium for reliable publishing; idempotent consumers.
- Checkout saga orchestrated (visibility, compensation); fulfilment, notifications and analytics choreographed via events.
sequenceDiagram
participant C as Client
participant CHK as Checkout
participant INV as Inventory
participant PAY as Payment
participant ORD as Order
participant K as Kafka
C->>CHK: POST /orders (quoteId, Idempotency-Key)
CHK->>ORD: create order PAYMENT_PENDING
CHK->>INV: reserve stock (TTL 15 min)
INV-->>CHK: reserved
CHK->>PAY: authorize(amount, token)
alt authorized
PAY-->>CHK: authorized
CHK->>ORD: confirm order
ORD->>K: OrderConfirmed (outbox)
CHK-->>C: 201 CONFIRMED
else declined / timeout
PAY-->>CHK: declined
CHK->>INV: release reservation
CHK->>ORD: mark FAILED
CHK-->>C: 402 payment declined
end18. Cloud deployment architecture
- AWS (could equally be Azure/GCP): two active regions per geography (e.g. Mumbai + Hyderabad, Frankfurt + Ireland), each with 3 AZs.
- EKS clusters per region per environment; Karpenter for node autoscaling with Graviton + Spot for stateless workloads.
- Cell-based deployment: customers hashed into cells (each cell = full stack slice for cart/checkout/order) to limit blast radius; catalog and search shared.
- Multi-account landing zone: separate accounts for payments (PCI), shared services, workloads, logging, security.
- Data residency: EU cells only in EU regions.
19. CI/CD and DevOps
- Trunk-based development, PR checks (unit, contract tests with Pact, SAST, dependency scan).
- Build once, sign images, deploy via GitOps (Argo CD) to dev → staging → prod cells.
- Progressive delivery: canary per cell with automated analysis (error rate, latency, business KPIs such as checkout conversion) using Argo Rollouts; automatic rollback.
- Infrastructure as code (Terraform/CDK); policy as code (OPA/Kyverno).
- Feature flags for risky changes and sale-day kill switches.
- Load tests at 3× expected sale peak two weeks before events; game days.
20. Monitoring and observability
- OpenTelemetry everywhere; traces across BFF → services → DB.
- SLOs: checkout success rate, add-to-cart latency, search latency, payment authorization success by PSP.
- Business metrics in real time: orders per minute, GMV, conversion, payment decline rate by method; anomaly detection pages on sudden drops.
- Dashboards per cell; burn-rate alerts; synthetic checkout every minute per region.
21. Scalability and performance optimization
- CDN offload > 90% of bytes; edge-rendered product pages.
- Virtual waiting room for sale launches to admit users at a safe rate.
- Inventory hot SKUs: allocate stock into N Redis buckets per SKU for flash sales; reservations decrement atomically; reconciled to Aurora asynchronously; Aurora remains source of truth.
- Queue-based order intake during extreme peaks: accept order request, return "processing", confirm within seconds.
- Read replicas for order history; archive orders older than 2 years to S3/Iceberg.
- Search: separate indices per locale, replicas scaled for read QPS, query result caching.
22. High availability and disaster recovery
| Capability | Pattern | RPO | RTO |
|---|---|---|---|
| Browse, search | Active-active regions, CDN serves stale on origin failure | n/a | ~0 |
| Cart | DynamoDB global tables (eventual) | seconds | minutes |
| Checkout, orders, payments | Primary region per cell + Aurora Global Database warm standby | ~1 s | 15 min |
| Analytics | S3 cross-region replication | hours | 1 day |
Immutable backups in a separate account; quarterly regional failover game day per cell.
23. Cost optimization
- CDN and image optimization (AVIF/WebP, right sizes) cut egress, usually the biggest variable cost.
- Graviton/ARM instances and Spot for stateless pods; Savings Plans for the baseline.
- Scale-to-near-zero for non-production overnight.
- DynamoDB on-demand for spiky tables, provisioned + autoscaling for steady ones.
- Log sampling and retention tiers; drop debug logs in prod.
- Unit metric: infrastructure cost per order, tracked per team.
24. Architecture trade-offs and alternatives
| Decision | Chosen | Alternative | When the alternative is better |
|---|---|---|---|
| Service granularity | ~15 domain services | Modular monolith | Fewer than ~5 teams or early-stage product |
| Checkout coordination | Orchestrated saga | Choreography | Very simple flows with 2–3 steps |
| Inventory reservation | At checkout with 15-min TTL | At add-to-cart | Very limited stock (tickets, drops) |
| Multi-region | Active-active browse, warm standby checkout | Full active-active checkout | When RTO ≈ 0 justifies multi-region writes (Spanner/DSQL) |
| Search | Self-managed OpenSearch | Managed SaaS search | Small team, fast time-to-market |
| Buy vs build | Build core commerce | Buy platform (Shopify Plus, commercetools, SAP Commerce) | When commerce is not the differentiator |
25. Technology stack recommendations
| Layer | Recommendation |
|---|---|
| Frontend | Next.js, React, TypeScript, Tailwind, image CDN |
| Mobile | Kotlin, Swift (or React Native) |
| Backend | Java 21/25 + Spring Boot, Go for edge services |
| Data | Aurora PostgreSQL, DynamoDB, OpenSearch, Valkey, S3 + Iceberg |
| Messaging | Kafka (MSK), SQS for task queues |
| Orchestration | Temporal or Step Functions |
| Platform | EKS, Karpenter, Argo CD/Rollouts, Terraform, OpenTelemetry, Grafana stack |
| ML | SageMaker or Vertex AI, feature store, vector index |
| Security | Cognito/Auth0, WAF, KMS, Secrets Manager, Snyk/Trivy |
26. Common architecture mistakes
- Splitting into dozens of microservices before team boundaries exist ("distributed monolith").
- Shared database between services, making independent deploys impossible.
- Synchronous call chains on the product page (recommendations, reviews, ads) without timeouts.
- Reserving stock in the cart without expiry, causing phantom out-of-stock.
- No idempotency on order creation, leading to duplicate orders on retries.
- Caching prices for minutes, so the charged price differs from the displayed one.
- Treating the cache as optional while the DB cannot survive a cache failure.
- Sale-day readiness tested at normal load only.
- Bringing card data into own systems, exploding PCI scope.
27. Senior architect interview questions and answers
How do you prevent overselling during a flash sale of 10,000 units?
Use atomic conditional decrements (SQL UPDATE ... WHERE available >= qty or DynamoDB conditional writes) so that stock can never go negative. For extreme contention, pre-split the 10,000 units into buckets in Redis, decrement atomically, and reconcile to the database. Admit users through a waiting room, give reservations a TTL, and release them on payment failure.
How do you guarantee the price shown is the price charged?
Generate a signed, time-limited quote at checkout that freezes price, promotions, shipping and tax. Order creation references the quote ID; if it expired or the cart changed, re-quote and show the user the new total before charging.
The payment provider times out after authorization may have happened. What do you do?
Do not retry blindly with a new request. Retry with the same idempotency key, or query the PSP for the payment status. Keep the order in PAYMENT_PENDING, use a reconciliation job and PSP webhooks to resolve, and never mark it failed until the status is known.
Why Aurora for orders but DynamoDB for the cart?
Orders need multi-row ACID transactions, constraints, reporting queries and auditability. Carts are high-volume, simple key-value access with TTL where eventual consistency is acceptable and serverless scaling is valuable.
28. Enterprise architect interview questions and answers
How would you govern 15 teams building commerce services?
Publish domain boundaries (capability map → bounded contexts), standards (API style guide, event naming, observability, security baselines) as paved-road templates, and a lightweight architecture review for cross-domain changes. Track compliance through automated checks rather than meetings, and use ADRs for decisions that affect more than one team.
Build vs buy for the commerce platform?
Assess differentiation: if catalog/checkout is commodity, buy a composable commerce platform and differentiate on experience, logistics and data. If scale, speed of experimentation and marketplace features are the differentiator (as for a top-tier retailer), build the core with selective SaaS (search, tax, fraud, payments).
How do you migrate from the monolith safely?
Strangler fig: put an edge router in front, extract read-heavy domains first (catalog, search), then cart and checkout behind feature flags, synchronizing data with CDC during transition, and retire monolith modules once traffic reaches zero.
29. CTO-level business and technology questions
What is the business case for re-architecture?
Quantify current losses (failed checkouts at peak × average order value, lost conversion from slow pages, slow release cadence delaying revenue features) against investment (team cost, migration risk, cloud cost changes). Present phased value: sale-day stability in phase 1 pays for later phases.
How do you reduce cost per order by 25%?
Measure unit cost per service, then: CDN offload and image optimization, ARM + Spot, rightsizing from utilization data, commitment discounts on baseline, removing over-provisioned non-prod, log volume controls. Make teams accountable for their unit-cost KPI.
What are the top technology risks for the next sale?
Untested peak capacity, third-party PSP limits, a bad deployment during the event (enforce change freeze and canaries), and data store hot spots. Mitigate with load tests, PSP failover routing, freeze windows and game days.
30. Real-world implementation roadmap
| Phase | Duration | Outcomes |
|---|---|---|
| 0. Foundations | 0–3 months | Landing zone, EKS platform, CI/CD, observability, edge (CDN/WAF), waiting room, load-test harness |
| 1. Browse | 3–6 months | Catalog + search extracted via strangler; CDC from monolith; SSR web |
| 2. Cart & checkout | 6–10 months | Cart, pricing quotes, checkout saga, payment service with PSP tokens; idempotency everywhere |
| 3. Orders & inventory | 9–14 months | Order and inventory services, outbox events, fulfilment integration; monolith order module retired |
| 4. Scale & resilience | 12–18 months | Cells, multi-region DR, sale-day automation, cost optimization |
| 5. Intelligence | 15–24 months | Recommendations, personalized search ranking, GenAI shopping assistant |
Success measures per phase: checkout success at peak, p95 latencies, deployment frequency, change failure rate, cost per order.