Module 12 · Shared contract

Shared Capstone Specification

Một business problem duy nhất để hai implementation WebFlux và Vert.x so sánh công bằng.


1. Domain

EntityFields chính
Userid, status
Orderid, userId, status, total, idempotencyKey
OrderItemsku, quantity, unitPrice
InventoryReservationorderId, sku, qty, status
PaymentpaymentId, orderId, status, amount
OrderEventorderId, type, timestamp, payload

2. API Contract

POST /orders
GET  /orders/{id}
GET  /users/{id}/orders
POST /orders/{id}/cancel
GET  /orders/{id}/events   (SSE)

POST /orders dùng Idempotency-Key.

3. Create Order flow

Validate → Find User → Reserve Inventory → Price → Payment → Persist Order → Publish Event → 201

4. Failure rules

FailureBehavior
User not found404.
Insufficient inventory409.
Payment timeout503/domain timeout.
Duplicate idempotency keyReturn same outcome nếu request tương đương.
DB fail sau paymentCompensation/reconciliation.
Publish event failOutbox/retry strategy.

5. Schema

CREATE TABLE orders (
  id BIGSERIAL PRIMARY KEY,
  user_id BIGINT NOT NULL,
  status VARCHAR(32) NOT NULL,
  total NUMERIC(18,2) NOT NULL,
  idempotency_key VARCHAR(128) UNIQUE NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

6. Timeouts

  • User 500 ms.
  • Inventory 700 ms.
  • Payment 1500 ms.
  • Overall create-order 3 s.

7. Shared test scenarios

  1. Happy path.
  2. User 404.
  3. Inventory conflict.
  4. Payment timeout.
  5. Duplicate key.
  6. Cancel.
  7. SSE events.
  8. Slow DB.
  9. Client disconnect.
  10. Concurrent duplicate POST.

8. Parity

Cùng API, schema, business rules, timeout budget, downstream mock và load workload. Chỉ implementation model khác.