Part 05 · Execution · 5.3A

API, networking và security: execution labs

Tập trung vào request bị retry, response bị mất, authorization theo object và network timing thay vì chỉ happy-path controller. Mọi lab phải giữ evidence đã redacted và có gate định lượng.

Safety: chạy trong local/staging cô lập, dùng fixture giả, không dùng credential thật hoặc public target. Ghi version/config, command, timestamps và cleanup.

Lab A · Idempotent POST và lost response

create table idempotency_records (principal_id, operation, key, request_hash, resource_id, status, response, primary key(principal_id, operation, key));
  1. POST payment/order với Idempotency-Key; persist key, fingerprint và effect atomically.
  2. Gửi 20 concurrent requests cùng key/payload.
  3. Commit DB rồi proxy/test hook drop response đầu tiên; client retry cùng key.
  4. Gửi cùng key nhưng payload/amount khác.
  5. Thiết kế TTL dài hơn retry/reconciliation window và chạy cleanup.

Assertions

Lab B · Timeout budget qua nhiều hop

client deadline 2000ms; gateway budget 1800ms; service DB + downstream budget 1500ms; retry attempts nằm trong remaining deadline
  1. Inject DNS/connect/TLS/first-byte/body delays riêng.
  2. Đo phase timing và connection-pool wait bằng một trace ID.
  3. Tạo nested retries ở gateway/service rồi đo amplification.
  4. Chuyển retry ownership về một layer, thêm jitter/cancellation.

Gate: có waterfall/timeline, downstream attempts trước/sau fix, queue/pool occupancy và tổng latency nằm trong deadline.

Lab C · Object-level authorization

  1. Tạo user A/B, account/order thuộc A và token B có role hợp lệ.
  2. Test B đọc/update/delete object A, đổi path/body owner ID và thử mass assignment.
  3. Test expired/wrong audience/missing scope; phân biệt 401 và 403.
  4. Audit denied decisions có correlation nhưng không log token/PII.
  5. Rate-limit theo principal + operation; kiểm tra NAT/shared-IP caveat.

Gate: role hợp lệ không bypass ownership; admin override explicit và audit được; query scope không dựa trên UI.

Deliverables và Definition of Done

Review gate: reviewer phải tái chạy được fixture từ README/runbook, thấy expected failure trước fix và control sau fix, mà không cần secret ngoài phạm vi.