Written on 13th April 2026 by Carter Phan.
Saga = chuỗi các transaction local + rollback (compensation) nếu có lỗi
Dùng khi:
Trong monolith:
BEGIN TRANSACTION
→ Update A
→ Update B
COMMIT / ROLLBACK
ACID đảm bảo consistency
Trong microservices:
Service A → Service B → Service C
Không có global transaction
Nếu B fail → A đã commit rồi
Thay vì rollback DB transaction →
Dùng compensation actions
1. Create Order (Order Service)
2. Reserve Inventory (Inventory Service)
3. Charge Payment (Payment Service)
→ Compensate:
- Release Inventory
- Cancel Order
Không rollback DB
Roll forward bằng undo actions
| Choreography | Orchestration | |
| Control | Distributed | Centralized |
| Coupling | Low | Medium |
| Debug | Hard | Easier |
| Scale | High | Medium |
| Action | Compensation |
| Reserve inventory | Release inventory |
| Charge payment | Refund |
| Create order | Cancel order |
| Saga | 2PC | |
| Consistency | Eventual | Strong |
| Performance | High | Low |
| Complexity | Medium | High |
| Availability | High | Low |
Microservices → dùng Saga
Monolith / DB → dùng ACID / 2PC
Saga = distributed transaction without rollback, using compensation