Checkout Request Flow (Synchronous)
Async Order Processing (Decoupled from Checkout)
Product Service — ALB Automatic Target Weights (ATW) Demo

AWS ALB

Listener rules (priority):

  1. /product*
    → Product TG (ATW)
  2. /credit-card-authorizer/*
    → CCA TG
  3. /shopping-carts*
    → Cart TG

External + internal traffic.
Single stable DNS entry.

Load Tester

200k checkout requests
· 100 threads (FixedThreadPool)
· Pre-creates 100 carts
· CountDownLatch sync barrier

ATW demo:
50k GET /product requests

Runs on ECS Fargate
aws ecs run-task

Shopping Cart Service

Checkout steps:

  1. Validate cart + items exist
  2. Validate card format (regex)
  3. Sync call → CCA via ALB
    · 402 received → return 402, stop
  4. Borrow channel from pool (max 20)
  5. basicPublish → order_queue
    waitForConfirmsOrDie(5000ms)
  6. Return channel → respond 200

ConcurrentHashMap + AtomicInteger

Credit Card Authorizer

Card format regex:
^\d{4}-\d{4}-\d{4}-\d{4}$
→ 400 if invalid format

Response (ThreadLocalRandom):
200 Approved (90%)
402 Declined (10%) ← intentional

Stateless, no DB.

Triggers 10% of checkouts
to fail with 402.

Product Service · Good ×2

GET /product/{id} → 200 OK
POST /product → 201 Created
DELETE /product/{id} → 200 OK

ConcurrentHashMap + AtomicInteger

ALB weight: ~46% each
(shifted up by ATW after bad detected)

Product Service · Bad ×1

BAD_INSTANCE=true
50% of requests → 503 SERVICE_UNAVAILABLE
(ThreadLocalRandom)

/health → 200 OK ← health check passes!
But real traffic fails 50% of the time.

ALB weight: 33% → ~8% (ATW detects anomaly)

RabbitMQ Broker

Queue: order_queue
· durable = true (survives restart)
· exclusive = false
· autoDelete = false

Messages: PERSISTENT_TEXT_PLAIN
(written to disk before ACK)

Publisher Confirms: confirmSelect()
Shopping Cart blocks until broker ACKs.

AWS: rabbitmq.cs6650.local (Cloud Map)
Management UI: :15672

ATW — Automatic Target Weights

ALB monitors 5XX rate per registered instance.
When bad instance anomaly is detected:

· Algorithm: weighted_random (required for ATW)
· Setting: anomaly_mitigation = on
· Traffic shifts gradually over ~2 minutes

Weight shift:
Bad instance: 33% → ~8%
Good ×2: 33% → ~46% each

unhealthy_threshold = 10 keeps bad instance
registered intentionally (for demo visibility).

Warehouse Consumer

10 worker threads (FixedThreadPool)
Each thread: dedicated Channel

basicQos(10) — max 10 unacked per thread
autoAck = false — manual acknowledgement

On success: basicAck(tag, false)
On failure: basicNack(tag, false, requeue=true)
at-least-once delivery guarantee

Shared state (thread-safe):
ConcurrentHashMap<productId, AtomicLong>
AtomicLong orderCount

Async Order Pipeline

Distributed e-commerce system on AWS ECS Fargate.
Microservices · RabbitMQ · ALB path routing · ATW anomaly detection

10% error rate is intentional — bad credit cards trigger 402 Payment Declined in CCA.