Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
(10分版)モダンアプリケーションにおける分散トランザクションの動機と実装パターン
Search
Yuji Nomura
April 25, 2023
Programming
3
6.3k
(10分版)モダンアプリケーションにおける分散トランザクションの動機と実装パターン
AWS Summit TokyoのLTでお話ししました!AWSサービスの話はほとんどないです。
Yuji Nomura
April 25, 2023
Tweet
Share
More Decks by Yuji Nomura
See All by Yuji Nomura
モダンアプリケーションにおける分散トランザクションの動機と実装 @ AWS Dev Day 2023 Tokyo
ugnom
14
5.8k
Other Decks in Programming
See All in Programming
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
3.8k
為你自己學 Python
eddie
0
540
ASP.NET Core の OpenAPIサポート
h455h1
0
170
Moscow Python Meetup №97. Константин Крестников (Техлид команды GigaChain (SberDevices)). GigaChain: Новые инструменты для разработки агентов на примере агента техподдержки
moscowdjango
PRO
0
100
functionalなアプローチで動的要素を排除する
ryopeko
1
990
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
2.7k
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
0
130
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
2.4k
ErdMap: Thinking about a map for Rails applications
makicamel
1
1.2k
振り返れば奴(Cline)がいる
keiyagi
0
140
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
390
Vue.jsでiOSアプリを作る方法
hal_spidernight
0
120
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
380
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
990
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Git: the NoSQL Database
bkeepers
PRO
427
64k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Adopting Sorbet at Scale
ufuk
74
9.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
BBQ
matthewcrist
85
9.4k
Transcript
© 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
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. モダンアプリケーションにおける 分散トランザクションの 動機と実装パターン Yuji Nomura M I N I - 8 Sr. Solutions Architect, Enterprise Majority Focused Amazon 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 サービスB A⽤ 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. 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. トランザクションを分割するパターン コレオグラフィ 同⼀DBの トランザクション処理 データの関係性 後続処理失敗の前段への影響 ⼀貫性 Saga パターン 疎 密 無し 多⼤ 強い 弱い ⼆相コミット 結果整合 強整合 オーケストレーション 情報共有的な データ伝播 Event
© 2023, Amazon Web Services, Inc. or its affiliates. All
rights reserved. ⼆相コミットはトレードオフを気にする • ⼆相コミットのリスク︓ • ロックの待ち時間によるレイテンシーの増加 • 通信障害などによるロック状態の固定 第1フェーズ 第2フェーズ commit OK? 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. トランザクションを分割するパターン コレオグラフィ 同⼀DBの トランザクション処理 データの関係性 後続処理失敗の前段への影響 ⼀貫性 Saga パターン 疎 密 無し 多⼤ 強い 弱い ⼆相コミット 結果整合 強整合 オーケストレーション 情報共有的な データ伝播 Event
© 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 session survey in the mobile app Yuji Nomura
[email protected]
twitter: @ugnomura