중복 시작과 중단 후 재개

같은 IdempotencyKey는 하나의 OrderId로 모이고, 재개는 stream을 replay한 뒤 다음 단계부터 이어간다

중복 시작과 중단 후 재개 같은 IdempotencyKey는 하나의 OrderId로 모이고, 재개는 stream을 replay한 뒤 다음 단계부터 이어간다 [par] StartOrderReq(same IdempotencyKey) [par] Reserve mapping [par] StartOrderReq(same IdempotencyKey) [par] Reserve mapping One OrderId Same OrderId StartOrderWorkflowReq StartOrderWorkflowReq Deduplicate SourceCommandId StartOrderWorkflowRes StartOrderWorkflowRes Replay OrderId stream InventoryReserved state AuthorizePaymentReq(existing PaymentId) Authorization result Append Payment event with expected version Client A · Sequence participant Client A Client B · Sequence participant Client B CommerceApi A · Sequence participant CommerceApi A CommerceApi B · Sequence participant CommerceApi B Commerce State · Sequence participant Commerce State OrderWorkflow · / Order Spot · Sequence participant OrderWorkflow / Order Spot Order Event Store · Sequence participant Order Event Store Payment · Sequence participant Payment

mermaid par 블록 (archify에는 동시성 표현이 없어 평평하게 폈다)

  • • 1~4번([par] 표시)은 순차가 아니라 동시에 실행된다 — Client A/B가 같은 IdempotencyKey로 동시에 시작을 요청하고, 각 CommerceApi가 동시에 mapping을 예약한다.

Recovery replays the stream before choosing the next step

  • • mermaid Note over Workflow,Events(12번 Replay OrderId stream 앞에 위치): 'Recovery replays the stream before choosing the next step.'
  • • 동시 시작에서는 CommerceStateStore의 mapping reservation에서 먼저 성공한 요청이 OrderId를 결정한다. 다른 요청은 자신의 후보 ID를 버리고 같은 ID를 사용한다. SourceCommandId가 이미 stream에 있으면 Workflow는 event를 다시 기록하지 않고 fold 결과를 반환한다.
  • • 재개는 새 workflow 코드를 만들지 않는다 — stream을 replay해 마지막으로 기록된 상태(InventoryReserved)를 확인하고, 이미 완료한 예약 단계를 건너뛰어 결제부터 실행한다.