網頁

2023/4/10

系統設計 遠端資源狀態一致性問題 - 遠端資源A已建立但B建立失敗


資源的建立有順序性,先有A才能有B,且B要建立完成A才算建立完成,否則A建立失敗。建立B時失敗則做補償交易的狀況。



plantuml

@startuml
participant client
participant app
database    db
participant remote
skinparam sequenceMessageAlign center
skinparam ParticipantPadding 50

client ->> app : create request
activate app
app -->> client : accepted
app -> db : CREATE record A\n with state 'building'
activate db
db -->> app : success
deactivate db
|||
app -> remote : CREATE resource A
activate remote
remote -->> app : success
deactivate remote
|||
app -> db : CREATE record B\n with state 'building'
activate db
db -->> app : failed 
note over db : record B not created
deactivate db
|||
app -> remote : DELETE resource A
note over remote : compensating transaction
activate remote
remote --> app : success
deactivate remote
|||
app -> db : UPDATE record A state\n to 'create-failed'
activate db
db -> app : success
deactivate db
|||
app ->> client : failed message
deactivate app
@enduml

動作步驟:

  1. create A record
  2. create A resource
  3. create B record (failed)
  4. delete A resource (compensating)
  5. update A record (compensating)

沒有留言:

張貼留言