Saga pattern chia distributed transaction thành chuỗi local transaction — mỗi service update DB của mình và publish event qua RabbitMQ.
Có 2 cách:
- Choreography: mỗi service lắng nghe event và publish event của mình (phi tập trung, khó trace).
- Orchestration: một coordinator service điều phối từng bước (tập trung, dễ hiểu hơn)
Ví dụ order saga: payment service (trừ tiền) → inventory service (giữ hàng) → shipping service (lên lịch giao).
Nếu một bước fail, compensating transaction chạy ngược lại.
The saga pattern breaks distributed transactions into a series of local transactions coordinated via events published to RabbitMQ.
Two approaches:
- Choreography — each service listens for events and publishes its own (decentralized, hard to trace).
- Orchestration — a central coordinator directs each step (centralized, easier to understand)
If any step fails, compensating transactions execute in reverse.