Module 14 · Runnable capstone guide
Capstone B — Reactive Order Platform bằng Vert.x
Implementation guide cho cùng business spec bằng Vert.x Future, Event Bus, Web và SQL Client.
1. Architecture
Router/HttpVerticle → OrderService(Future)
├─ SQL Client
├─ EventBus→InventoryVerticle
└─ WebClient→Payment
↓
EventBus→SSE bridge2. Create flow
Future<OrderResponse> create(CreateOrder cmd, String key) {
return idempotency.find(key)
.compose(existing -> {
if (existing != null) return Future.succeededFuture(existing);
return userService.requireActive(cmd.userId())
.compose(v -> reserveInventory(cmd))
.compose(v -> payment.charge(cmd, key))
.compose(p -> save(cmd, p, key))
.compose(order -> publishCreated(order)
.map(v -> OrderResponse.from(order)));
});
}3. Event Bus
Dùng Event Bus nơi loose coupling có lợi thật sự. Không biến mọi local call thành message.
4. SQL transaction
Dùng pool.withTransaction cho DB-local changes. External payment nằm ngoài ACID transaction.
5. SSE
Register consumer theo orderId, unregister khi connection đóng, theo dõi write queue để tránh slow-client memory growth.
6. Tests
- Deploy verticles trong test.
- HTTP contract parity.
- DB fixture giống WebFlux.
- Mock payment giống nhau.
- EventBus timeout/failure.
- Concurrent idempotency.
7. Observability
- Event-loop delay.
- Worker saturation.
- SQL pool utilization.
- HTTP client latency.
- EventBus timeout.
8. Checklist
- ☑ No JDBC on event loop.
- ☑ Future composition.
- ☑ Clear EventBus contracts.
- ☑ SQL transaction.
- ☑ Payment timeout.
- ☑ Idempotency.
- ☑ SSE cleanup.
- ☑ Test parity.
9. Challenge
Deploy nhiều OrderVerticle instances và phân tích state nào không được để local-memory nếu muốn scale ngang.