AWS Summit TokyoのLTでお話ししました!AWSサービスの話はほとんどないです。
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.T O K Y O | A P R I L 2 1 , 2 0 2 3
View Slide
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.モダンアプリケーションにおける分散トランザクションの動機と実装パターンYuji NomuraM I N I - 8Sr. Solutions Architect, Enterprise Majority FocusedAmazon Web Services Japan
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.• モダンアプリケーションの⽬的とトランザクションへの影響• トランザクション分割の⽅針• (分散)トランザクション実装パターン⽬次
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.モダンアプリケーションの⽬的とトランザクションへの影響
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.アプリケーションのモダン化モダンなアプリケーションアーキテクチャといえば︓• マイクロサービス• サーバーレス• コンテナ→ ⽐較的⼩さなデプロイ単位で独⽴して運⽤するための仕組み
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.デプロイ独⽴性のメリット• チームの⾃律• 開発からリリースまでのスピード感• 可⽤性・スケーラビリティ・弾⼒性
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービスA サービスBA⽤ B⽤ ⾃分のエリアを跨いだやりとりサービスAPIマイクロサービスの性質を考えてみる
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.サービスA サービスBA⽤ B⽤変更が伝播サービスAPIマイクロサービスの性質を考えてみる
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.A⽤ B⽤• 直接更新はできない• 要件⾃体は残るサービスA サービスBサービスAPIマイクロサービスの性質を考えてみる
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.トランザクション分割の⽅針
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.開発者たちは、アトミックな変更が必須であると洗脳されているのが⼀般的だ。(しかし)ドメインエキスパートたちは整合性を保つのに時間がかかったとしても、それが合理的な遅延であれば受け⼊れてくれるものだ。実践ドメイン駆動設計 / Vaughn Vernon第⼗章 集約 10.5.「ルール︓境界の外部では結果整合性を⽤いる」
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.整合性の種類同期 強整合性⾮同期 結果整合性
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.まず結果整合性を検討する• 結果整合なトランザクション伝播の検討§ ビジネス整合性を保てるようにシステムの形を変更• 結果整合性が受け⼊れられない場合§ トレードオフを受け⼊れて結合度の⾼い⽅法を選択§ サービス境界の⾒直し
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.(分散)トランザクション実装パターン
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.トランザクションを分割するパターンコレオグラフィ オーケストレーション同⼀DBのトランザクション処理データの関係性後続処理失敗の前段への影響⼀貫性Saga パターン疎 密無し 多⼤強い弱い⼆相コミット結果整合 強整合情報共有的なデータ伝播Event
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.トランザクションを分割するパターンコレオグラフィ同⼀DBのトランザクション処理データの関係性後続処理失敗の前段への影響⼀貫性Saga パターン疎 密無し 多⼤強い弱い⼆相コミット結果整合 強整合オーケストレーション情報共有的なデータ伝播Event
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.⼆相コミットはトレードオフを気にする• ⼆相コミットのリスク︓• ロックの待ち時間によるレイテンシーの増加• 通信障害などによるロック状態の固定第1フェーズ 第2フェーズcommitOK?OK!commit! 更新更新
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.CAP定理を思い出してみると何かを犠牲にしなくてはならない• 一貫性(Consistency)• 可用性(Availability)• 分断耐性(Partition tolerance)マイクロサービス化において分断耐性は絶対に外せない可用性も落とせないそうすると一貫性がどうしても犠牲になる
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.Saga パターンユーザーリクエストサービスリクエストキューサービスAサービスBサービスCサービスAサービスBサービスC
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.トランザクションを分割するパターン情報共有的なデータ伝播コレオグラフィ同⼀DBのトランザクション処理データの関係性後続処理失敗の前段への影響⼀貫性Saga パターン疎 密無し 多⼤強い弱い⼆相コミット結果整合 強整合Eventオーケストレーション
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.event[i-ʼvent] 名詞状態が変更されたことを⽰すシグナル
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.イベントは観察可能であり、指⽰ではないコマンドの指⽰請求書を発⾏してください。承知しましたイベントの観察Xさんが今⼩物を注⽂しました請求書を送りますセールスレポートに追加します。
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.信頼性、弾⼒性、独⽴したスケール性注⽂サービス請求サービス⼊⾦サービス販売予測サービスプロデューサコンシューマイベントルータールーティング/フィルタ/ルールキューキューキュー
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.まとめ• デプロイ独⽴性を考えるとデータベースの分割の観点からトランザクションが問題になってくることがある• 結果整合性を重視したアプリケーション設計を考える• 分散トランザクションの実装パターンは⾊々⽅法があるので要件によって使い分ける
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.Thank you!© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.Please complete the sessionsurvey in the mobile appYuji Nomura[email protected]twitter: @ugnomura