Saga Pattern
사가 패턴
사가는 여러 저장된 단계를 하나의 비즈니스 작업으로 연결합니다. 나중 단계에서 실패가 발생하면, 이전에 일어난 일을 수정하기 위해 다시 시도하거나 다른 단계를 추가합니다.
saga ID + local transaction -> next step; failure -> retry | compensation -> terminal state- ✓비행 보류flight_tx_7
- ✓카드 충전됨pay_tx_8
- !호텔 이용 불가hotel_tx_9
saga ID + local transaction -> next step; failure -> retry | compensation -> terminal stateJOB다른 예시
주문 `984`는 재고를 예약하고 NT$248를 승인한 후 배송을 요청합니다. 배송은 주소를 거부합니다. 사가는 승인을 취소하고 동일한 사가 ID로 재고를 해제합니다. 그런 다음 주문을 보상된 것으로 기록합니다.
주요 부분
- 01사가 ID 및 상태
- 02참여 서비스
- 03로컬 트랜잭션
- 04결과 메시지
- 05재시도 또는 보상
- 06감사 및 수동 복구
사용할 때
하나의 비즈니스 작업이 여러 서비스나 데이터 저장소에 걸칠 때 사가를 사용하세요. 전체 작업을 한 번에 처리할 수 있는 단일 데이터베이스 단계로는 충분하지 않을 때만 사용하세요. 저장된 각 단계, 다음 행동, 재시도, 수정 행동 및 최종 상태를 정의하세요.
다음 경우에는 사용하지 마세요
하나의 데이터베이스 저장으로 전체 작업을 완료할 수 있을 때는 사가를 추가하지 마십시오. 수정 작업은 새로운 작업입니다. 실패할 수 있거나 다른 결과를 남길 수 있습니다. 실행을 되돌리는 것이 안전하지 않을 때는 사람에게 물어보십시오.
코드에서 사용된 이름
saga ID + local transaction -> next step; failure -> retry | compensation -> terminal state 출시하기 전에
Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback.
Outcome:Complete the task with 사가 패턴 (Saga Pattern)。 User context:주문 `984`는 재고를 예약하고 NT$248를 승인한 후 배송을 요청합니다. 배송은 주소를 거부합니다. 사가는 승인을 취소하고 동일한 사가 ID로 재고를 해제합니다. 그런 다음 주문을 보상된 것으로 기록합니다. Technical concept or control:사가 패턴 (Saga Pattern)。 Why it fits:하나의 비즈니스 작업이 여러 서비스나 데이터 저장소에 걸칠 때 사가를 사용하세요. 전체 작업을 한 번에 처리할 수 있는 단일 데이터베이스 단계로는 충분하지 않을 때만 사용하세요. 저장된 각 단계, 다음 행동, 재시도, 수정 행동 및 최종 상태를 정의하세요. Do not use it when:하나의 데이터베이스 저장으로 전체 작업을 완료할 수 있을 때는 사가를 추가하지 마십시오. 수정 작업은 새로운 작업입니다. 실패할 수 있거나 다른 결과를 남길 수 있습니다. 실행을 되돌리는 것이 안전하지 않을 때는 사람에게 물어보십시오. Engineering requirements: Define inputs, outputs, contracts, and rules that must always hold. Set authorization and input checks. Define failures, timeouts, retries, one-time effects, data moves, and compatibility limits. Operations: Add useful signals and logs that hide sensitive data. Set capacity limits and write an operator guide. Test recovery and rollback. Acceptance criteria: Contract and failure-path tests pass. Data and authorization rules still hold during retries and partial failures. Check performance limits, monitoring, recovery, and rollback. Evidence and limits (evidence boundary):하나의 공식 표준이 전체 용어를 통제하지 않음. 의미는 팀, 플랫폼 또는 프레임워크마다 달라질 수 있음. Unknowns to confirm: Where the code runs, data stores, traffic shape, consistency needs, and the security boundary. Also confirm the compatibility period, service goals, and rollback limits.
이 요청을 확인하세요
Review how 사가 패턴 (Saga Pattern) is used now. Definition: 사가는 여러 저장된 단계를 하나의 비즈니스 작업으로 연결합니다. 나중 단계에서 실패가 발생하면, 이전에 일어난 일을 수정하기 위해 다시 시도하거나 다른 단계를 추가합니다. Release checks: Check contracts and invariants, authorization, and input limits. Test retries, one-time effects, timeouts, and partial failures. Verify data integrity, compatibility, monitoring, recovery, and rollback. Before changing code, list the evidence, gaps, severity, and the smallest safe fix.