Problems / Real world, hard

Amazon storefront: from launch build to real traffic

A storefront as first built: product pages read DynamoDB with no product cache, and the product, cart and checkout APIs, search, recommendations, the orders database, payments and fulfilment workers at an eighth of their real size. Shoppers arrive at real traffic and half of all requests fail, checkout included.

Unlock it once for 25 credits; everything inside it is free (runs, changes, Submit, results, hints). Sign in with Google to start; new accounts get free credits.

Your goals

Grow it into the real architecture: every goal must hold at 4,000 requests a second. You may add components, connect them and resize anything.

Test cases

Like a coding problem, a solution has to pass every case, not just the one it was built for. Submit in the lab runs all 6; 2 of them are hidden until then.

  1. As given. The problem’s own traffic, scheduled failures and seed.
  2. Peak hour. 25% more traffic than the problem states, with the same failures.
  3. A slow dependency. The main data store or model answers twice as slowly for part of the run.
  4. A server dies. One replica of the service with the most replicas is killed for part of the run.

The traffic

4,000 requests a second for 20 seconds: 70% browse (reads), 20% cart (writes), 10% checkout (writes).

The system

What each component does in this design, and what calls it. The simulator mimics each one from these settings.

ComponentIts job hereSettings
DDoS protectionDDoS protectionTraffic enters here.Calls WAF.Volumetric floods are absorbed at the network edge, spread over many locations, before they reach you.100000 slots
WAFWAFDDoS protection forwards to it.Calls API gateway.A WAF inspects HTTP requests for attacks such as SQL injection and cross-site scripting.100000 slots
API gatewayAPI gatewayWAF forwards to it.Calls Product API, Cart API, Checkout API.Gateways centralise auth, rate limits and routing so each service does not reimplement them.50000 slots · 1,200,000 calls/min
Product APIApp serviceAPI gateway forwards to it for /browse.Calls Catalog (DynamoDB), Search (OpenSearch), Recommendations.Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 1.0 s
Catalog (DynamoDB)Document databaseProduct API calls it for reads.Document databases store nested JSON-like records, so one read can fetch a whole aggregate.250 slots
Search (OpenSearch)Search indexProduct API calls it on 30% of requests.Search engines build an inverted index: each word points to the documents that contain it.64 slots
RecommendationsRanking modelProduct API calls it on 50% of requests.Feeds rank a few hundred candidates per load with a learned model; retrieval narrows millions of posts first.128 slots
Cart APIApp serviceAPI gateway forwards to it for /cart.Calls Carts (session store).Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 1.0 s
Carts (session store)Session storeCart API calls it.A shared session store lets any app server handle a user's next request.1250 slots
Checkout APIApp serviceAPI gateway forwards to it for /checkout.Calls Orders and stock (Aurora), Payment service, Order events (publishes).Little's law: throughput ≈ concurrency ÷ latency. 200 slots at 50 ms serve about 4,000 req/s.1 replicas × 100 slots · timeout 5.0 s
Orders and stock (Aurora)SQL databaseCheckout API calls it.Postgres runs one process per connection, which is why poolers like PgBouncer sit in front of busy databases.4 vCPU · 50 connections
Payment servicePayment gatewayCheckout API calls it.Calls Payment service (backup) (fallback).Payment providers accept an idempotency key so a retried charge is not taken twice.250 slots
Payment service (backup)Payment gatewayPayment service falls back to it on failure.Payment providers accept an idempotency key so a retried charge is not taken twice.250 slots
Order eventsMessage queueCheckout API publishes to it.Calls Fulfilment workers.If a consumer does not finish within the visibility timeout, the message is delivered again.–
Fulfilment workersWorkerOrder events consumes from it.Calls Order emails.Queues deliver at least once, so a worker can see the same message twice.16 concurrent jobs
Order emailsNotification serviceFulfilment workers calls it.Email, SMS and push providers all throttle senders and can delay delivery.25 slots · 125,000 calls/min

More real world problems