Upgrade to Pro — share decks privately, control downloads, hide ads and more …

実践!モノリスからマイクロサービス!Event Stormingによるドメイン駆動設計から実装まで / AWS_Dev_Day_2023_E_3

実践!モノリスからマイクロサービス!Event Stormingによるドメイン駆動設計から実装まで / AWS_Dev_Day_2023_E_3

AWS Dev Day 2023 Tokyo. E-3 「実践!モノリスからマイクロサービス!Event Stormingによるドメイン駆動設計から実装まで」

2023/06/23 at AWS Dev Day 2023 Tokyo

Atsushi Fukui

June 23, 2023
Tweet

More Decks by Atsushi Fukui

Other Decks in Technology

Transcript

  1. © 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. 実践︕モノリスからマイクロサービス︕ Event Stormingによるドメイン駆動設計 から実装まで 福井 厚 E - 3 シニアソリューションアーキテクト Developerスペシャリスト - DevAx アマゾンウェブサービスジャパン合同会社
  2. © 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. ⾃⼰紹介 v名前 v福井 厚(ふくい あつし)fatsushi@ v所属 vアマゾン ウェブ サービス ジャパン合同会社 vシニアソリューションアーキテクト Developer スペシャリスト - DevAx v関⼼領域 vソフトウェア アーキテクチャ、オブジェクト指向設計、アジャイル開発 v好きなAWSサービス vサーバーレステクノロジー全般、 AWS Code シリーズ、AWS Amplify
  3. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda • 本セッションについて • なぜマイクロサービスアーキテクチャを採⽤するのか • マイクロサービスに適した組織 • ドメイン分割を導くのためのEvent Storming • 実装に向けた⾮機能要件への適⽤ • ストラングラーパターンによる移⾏ • ドメインモデルからのインフラストラクチャコードの分離 • まとめ
  4. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 本セッションについて • 本セッションはDevAxチームの⽇々の活動を通じて得た経験を汎化して要約したも のです。従ってこの通りにすれば良いというものではなくモノリスからマイクロサ ービスへの分割の⼀例として参考にして頂ければ幸いです。 • 本セッションの対象者 § 現在モノリスなシステムで稼働しておりサービスの分割を検討しているCTO、 アーキテクト、デベロッパーなどの技術者の⽅ § サービスの整理、分割にドメイン駆動設計を適⽤されようとしている⽅及びAWS のサービスを活⽤してそれらを実装されようとしている⽅ • 本セッションで扱わない内容 § AWSの各サービスにおける仕様の詳細や料⾦などの情報 •
  5. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 本セッションについて(注意︕) • 本セッションはマイクロサービスアーキテクチャを推奨するものでは ありません。 • すべてのアーキテクチャパターンと同様、マイクロサービスにも メリット、デメリットがあり、銀の弾丸ではありません。 • ご⾃⾝の関係するシステムや組織、⼈材、課題を鑑みて マイクロサービスを採⽤するかは、ご⾃⾝でご判断ください。
  6. © 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. なぜマイクロサービスアーキテクチャを 採⽤するのか
  7. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. こういうことを聞いたことはありませんか︖ 今のシステムの使い勝⼿、 もう少し何とかならないかなあ。 機能の追加も 中々やってもらえないし。 前にお願いした機能が あればライバル会社に勝てる ので、何とかならない︖ 規模が⼤きい上にコードが複雑 に絡み合って密結合なので、 どこから⼿をつけて良いのか。 このままだと泥団⼦に なってしまう。 技術的負債を何とかしないと。 ビジネス部⾨から システム部⾨から
  8. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. マイクロサービスにリファクタリングする理由 デプロイの影響範囲を⼩さくする 機能的な⾃律性と単⼀責任の原則 開発速度の向上 スケーリングの最適化
  9. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. マイクロサービスが良い選択肢ではない場合 • ドメインが不明確 • サービスの境界を間違えるとコストがかかる可能性 • スタートアップ • マイクロサービスの複雑性が却って⾜枷に • COTS(市販品)ソフトウェア • 正当な理由がない • 「流⾏っているから」「他がやっているから」で始めるのは危険
  10. © 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. マイクロサービスに適した組織
  11. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. マイクロサービスの組織とチームビルディング • ⾃律的で意思決定する権限と責任を持つチーム • 開発したチームが運⽤も⾏う(You build it, you run it) • Two Pizza Team • すべてを所有
  12. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 参考︓チームトポロジー ストリームアラインドチーム ストリームアラインドチーム ストリームアラインドチーム 共有サービスプラットフォームチーム 内部プラットフォームチーム ][ セキュリティ コミュニティ・オブ・ プラクティス(CoP) プラットフォーム + ツール )( )( フィールドチーム (サポート、ソリューションアーキテクト、営業) O 製品機能のリクエスト ストリームアラインドチーム ビジネスに沿った⽬標を持つチーム イネーブリングチーム ストリームアラインドチームが 障害を克服するのを⽀援。 コンプリケイテッド・ サブシステムチーム 専⾨性が必要な機能を担当する 専⾨スキルを持つチーム コラボレーション ファシリテーション O )( フェデレーションサービス (X-as-a-Service) ][ データ サイエン スチーム サービスとしてのプラットフォーム キー: )( )( ][ * マシュー・スケルトン,マニュエル・パイス. チームトポロジー 価値あるソフトウェアをすばやく届ける適応型組織設計 (Japanese Edition). Kindle Edition.
  13. © 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. どうやってサービスを分割するのか
  14. © 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. ドメイン駆動設計によるサービスの分割
  15. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメイン駆動設計 (DDD) とは • ⾼品質なソフトウェアモデルを設計 するためのソフトウェア開発⼿法 • ユビキタス⾔語 ー ビジネスドメイン エキスパートと開発者の間の意思疎通と して利⽤される⽤語によってモデリング と設計を⾏う • 戦略的な設計のためのガイドライン ー 境界づけられたコンテキスト、 蒸留、⼤規模な構造の考察 • 戦術的な設計 – 集約、エンティティ、 値オブジェクト、ドメインサービス 「エリック・エヴァンスのドメイン駆動設計」︓エリック・エバンス著 2011/4/9 翔泳社 「実践ドメイン駆動設計」︓ヴォーン・ヴァーノン著 2015/3/16 翔泳社
  16. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメイン駆動設計(DDD)とは 「DDDには戦略的モデリングと戦術的モデリングの両⽅の ためのツールが⽤意されており、業務要件を満たす⾼品質な ソフトウェアを設計するために、必要に応じて使える。」 ヴァーン・ヴァーノン. 実践ドメイン駆動設計 (Japanese Edition) (Kindle Locations 744-746). Kindle Edition.
  17. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 戦略的設計 • ビジネスドメインを理解する • 境界づけられたコンテキストからサブドメインを定義する • コンテキストマッピングを定義する
  18. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ビジネスドメインの理解 境界づけられたコンテキスト ユビキタス⾔語 コンテキストの外側 ドメインエキスパート
  19. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 境界づけられたコンテキストでサブドメインに分割 “ビジネスドメイン 全体の中の⼀部分” オークション ユーザー 認証 ⽀払い 配送 在庫 通知 オークションビジネスドメイン
  20. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 境界づけられたコンテキスト • 境界づけられたコンテキストは特定の モデルを適⽤できる限定された範囲。 • コンテキストの境界を定めることで、 チームメンバーは何を⼀致させるべきで 何を独⽴して開発できるのかについての 理解を明確化し、共有できる。 • これはサービスの境界になり得る https://www.martinfowler.com/bliki/BoundedContext.html Customer Ticket Product Product version Customer Product Territory Opportunity Pipeline Salesperson Defect Sales context Support context
  21. © 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. ドメイン分割を導くのための Event Storming
  22. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event Stormingの概要 • ⾼品質なモデリングのための 簡単なワークショップ • ドメインエキスパートと開発者 が協⼒して実施 • 業務から、境界づけられた コンテキストとモデルを 導き出す
  23. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event Stormingの流れ - Big Picture • Eventの洗い出し、時系列化 • Pivotal Event (分割点になるEvent )をマーク • スイムレーン(並⾏処理、分岐点) の発⾒ • 関係者/外部システムを洗い出し • 上記完了後に、ナレーション/ ウォークスルー
  24. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event Stormingの流れ – Process Modeling • 洗い出したイベントをつなぎプロセスに § コマンド § ロール § リードモデル § ポリシー § システム § ホットスポット https://www.slideshare.net/ziobrando/software-design-as-a-cooperative-game-with-eventstorming/27
  25. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Event Stormingの流れ –Software Design • 集約を⾒つける、名前をつける • 境界づけられたコンテキストを⾒つける • 設計の詳細に⼊り、コーディングに進められるようにする
  26. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step1 - ドメインイベントの洗い出し
  27. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step2 - 時系列に並べ替え
  28. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step3 - Pivotal Eventをマーク
  29. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step4 - スイムレーンの洗い出し
  30. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step5 - 関係者、外部システムの洗い出し ....
  31. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step6 - コマンドの追加 ....
  32. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step7 - アクターとポリシーの洗い出し ....
  33. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step8 - リードモデルの追加 ....
  34. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step9 - 集約を⾒つける
  35. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Step10 – 境界づけられたコンテキストを⾒つける ....
  36. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サブドメインに分割(再掲) “ビジネスドメイン 全体の中の⼀部分” オークション ユーザー 認証 ⽀払い 配送 在庫 通知 オークションビジネスドメイン
  37. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 境界づけられたコンテキストとドメインモデル 在庫 オークション ⽀払い 台⾞ ピッカー 配送サービス 倉庫 商品 棚位置 サイズ 重さ 配送顧客 配送先 ⼊札 落札 商品 SKU 画像 価格 ⼊札顧客 ID 検索サービス 落札顧客 クレジットカード ⽀払い
  38. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. データソースをサービスの所有ごとに分割 ⽀払い オークション 在庫 共有されている モノリシック データベース モノリシックシステム ⽀払い オークション 在庫 商品や顧客などもサービスによって利⽤する属性が 異なるので、それぞれのサービスの所有するデータ へ移⾏する。 データソースの移⾏計画も検討。 顧客マスタ 配送顧客 ⼊札顧客 ⽀払顧客
  39. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 戦術的設計 • 集約、値オブジェクト、エンティティー • ドメインイベント 39
  40. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 値オブジェクト • 構成要素の値によって識別されるオブジェクト • 識別⼦(ID)を必要としない • 例えば「⾊」値オブジェクト • イミュータブルで変更する 場合は全体を置き換え class Color { private _red:number; private _green:number; private _blue:number; constructor(red:number, green:number, blue:number){ this._red = red; this._green = green; this._blue = blue; } //...other methods }
  41. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. エンティティ • 明確な識別⼦(ID)を必要とする • エンティティーはライフサイクルを持つ • エンティティーは更新可能 • 例えばPersonエンティティ class Person { private _id:string; private _name:string; constructor(id:string, name:string){ this._id = id; this._name = name; } //... }
  42. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 集約 • 同⼀のトランザクション境界に属するエンティティと値オブジェクト の組み合わせ • 集約もエンティティなのでIDが必要 • 集約がトランザクションの単位 集約の ルート エンティティ 値オブジェクト エンティティ 1 0…* 1…* 1 ID
  43. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 例 – オークションの集約 オークション 競売参加者 オークション品 1 * 1 ⽀払い⽅法 配送⽅法 * 1 1 1 43 集約ルート 在庫 1 1 競売⼈ 1 1 *
  44. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 集約のルール • 集約はシンプルに⼩さく保つ • 集約の状態はパブリックインターフェイスでのみ変更可能 • 集約はトランザクション境界、集約の状態変更は アトミックな操作としてコミットする必要がある • 集約内のエンティティや値オブジェクトを表現する集約ルートを選択
  45. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 集約の関連 • 他の集約への参照としてIDを利⽤ • 他の集約の更新はドメインイベントを利⽤した結果整合 境界づけられた コンテキスト 1 境界づけられた コンテキスト 2 ドメインイベント 集約 1 集約 2
  46. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. イベント駆動アーキテクチャの利⽤ • イベント駆動アーキテクチャについては、以下のシリーズを参照 • AWS DevAx::Connect シーズン1「イベント駆動」 • https://aws.amazon.com/jp/devax-connect-on-demand/
  47. © 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. 実装に向けた⾮機能要件への適⽤
  48. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメインモデル DDD-Event Storming AWS サービス Well-Architected の 原則 概念モデル 論理モデル 物理モデル 現在の課題 技術的な課題 ⾮機能要件 システムデザイン パターン ベストプラクティス 境界づけられたコンテキスト コンテキストマップ 集約 論理アーキテクチャ システムコンポーネント ドメインコンポーネント システム構成要素 物理アーキテクチャ AWSサービス上の 意思決定 アーキテクチャの意思 決定を記録 ネットワークゾーン デプロイメント単位 ノード 機能説明 ドメインモデルから物理アーキテクチャへ
  49. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 論理アーキテクチャへのマッピング 品質特性 ⾮機能要件 論理アーキテクチャ 性能効率性 スケーラビリティーの担保、スロットリング要件など (例)ピーク時 1,000リクエスト/秒のリクエスト APIゲートウェイコンポーネント セキュリティー IDプロバイダの要件、認可要件など。 (例)認証されたリクエストのみが認可された権限範 囲でAPIにアクセス可能 認証プロバイダコンポーネント 信頼性 可能性の要件、サービスの稼働率など。 (例)疎結合な連携で⼀部のAZで障害が発⽣してもサ ービスを継続 メッセージキューコンポーネント 保守性 障害発⽣の検知など (例)サービスにまたがるモニタリング、ロギング 集約ログコンポーネント、可視化 コンポーネント ... ... ...
  50. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 参考︓ソフトウェア品質モデル ISO/IEC 25010:2011(JISX 25010: 2013) ソフトウェアの品質モデル 「JIS X 25010︓2013 システム及びソフトウェア製品の品質要求及び評価(SQuaRE)­システム及びソフトウェア品質モデル」より
  51. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 論理アーキテクチャから物理アーキテクチャへ • アーキテクチャの意思決定を記録する § なぜそのアーキテクチャを選択したのか • 付加価値を⽣まない重労働をクラウドのサービスにオフロードする § サーバーレスやマネージドサービスを活⽤ • デプロイメント単位を決定し頻繁にリリース可能にする § CI/CDによる⾃動化 • ⽇々の運⽤で知⾒を蓄え可観測性を⾼める § トレース、ログ、メトリクス、アラートの設定 このフェーズでは、ぜひお近くのSAにご相談を︕
  52. © 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. ストラングラーパターンによる移⾏
  53. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ビッグバンでの移⾏はお勧めしません︕ 終わりが⾒えない 。。。 今から丸3年かけて 2026年9⽉に マイクロサービス化した 新システムを リリースするぞー︕ 会社の偉い⼈ 現場の担当者
  54. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ビジネスドメインに従ってサービスを分割し ストラングラーパターンで徐々に移⾏ • ストラングラーパターン • レガシーアプリケーションのさまざまな コンポーネントのイベントと API を徐々に 作成して、モノリシックアプリケーションを マイクロサービスに移⾏する
  55. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス Store Front ユーザー インターフェイス 直接カットオーバーせず、 ストラングラーパターンを使⽤して リスクを軽減 ストラングラーパターンでモノリスから移⾏ 共有されている モノリシック データベース レガシーシステム ブラウザ
  56. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス 新機能 サービス レガシーシステム ブラウザ API ストラングラーパターンでモノリスから移⾏
  57. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス ユーザー マイクロサービス ACL(Anti-corruption layer) は、 境界づけられたコンテキスト間で 通信するための⼿段として使⽤される。 ACLが1 つのコンテキストから 別のコンテキストへ翻訳するので、 各コンテキストのモデルは独⽴を保ち ⾃⾝の⾔葉づかいを反映することができる ACL レガシーシステム ブラウザ 新機能 サービス API ストラングラーパターンでモノリスから移⾏
  58. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス レガシーシステム クライアント ブラウザ ユーザー マイクロサービス 新機能 サービス API API ストラングラーパターンでモノリスから移⾏
  59. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス レガシーシステム クライアント ブラウザ サービスがSSoT(※)になる ※Single Source of Truth ユーザー マイクロサービス 新機能 サービス API API ストラングラーパターンでモノリスから移⾏
  60. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス レガシーシステム クライアント ブラウザ キュー/エージェントを使⽤して同期 ユーザー マイクロサービス 新機能 サービス API API ストラングラーパターンでモノリスから移⾏
  61. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス カート サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス レガシーシステム クライアント ブラウザ カート マイクロサービス ACL ユーザー マイクロサービス 新機能 サービス API API API ストラングラーパターンでモノリスから移⾏
  62. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アカウント サービス ユーザー サービス 共有されている モノリシック データベース Store Front ユーザー インターフェイス レガシーシステム クライアント ブラウザ カート マイクロサービス ACL ユーザー マイクロサービス 新機能 サービス API API API アカウント マイクロサービス API ストラングラーパターンでモノリスから移⾏
  63. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Store Front ユーザー インターフェイス ブラウザ カート マイクロサービス ユーザー マイクロサービス 新機能 サービス API API API アカウント マイクロサービス API ストラングラーパターンでモノリスから移⾏
  64. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Migration Hub リファクタリングスペース リファクタリング環境 の設定と管理 にかかる時間を短縮 AWS Migration Hub リファクタリングスペース アプリの利⽤者を インフラの変更から保護 複数の AWS アカウント間 でトラフィックを旧→新に 再ルーティングする アプリケーションのリファクタリングを数か⽉ではなく数⽇で開始する
  65. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. • Leave and layer 別の出発点を提供 • 古いアプリケーションに触れることなく、 マイクロサービスの新機能でアプリを強化、 または拡張する • 新しい機能をlaunchするか、最⼩限のリスク で迅速にビジネスを拡⼤する Strangler Fig は、チームの独⽴性と最新の アプリアーキテクチャを実現するのに役⽴つ • リファクタリングする最初の部分との インターフェースを定義する • 新しい機能を設計、実装、テストする • 古いものから新しいものにリダイレクト • 古いコードまたはサービスを停⽌する 段階的にリファクタリングする 新機能をすばやくlaunchする アプリ変換のための複数の リファクタリングパターン
  66. © 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. ドメインモデルのインフラストラクチャ コードからの分離
  67. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 作成したドメインモデルをコードに反映 • TDD(テスト駆動開発)で実装 § ドメインモデルはピュアなビジネスロジックを実装するため テスト駆動開発と相性が良い § モデルと実装は繰り返し改善する § ドメインモデルとインフラストラクチャを分離する – 依存関係逆転の原則により、ドメイン層をシステム的な関⼼ごとから分離 – ヘキサゴナル/オニオン/クリーンアーキテクチャ
  68. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 参考︓ヘキサゴナルアーキテクチャ Domain Model Ports Adapters Primary Actor Secondary Actor HTTP Request Event Message Queue … File Storage Database Queue … アプリケーションはポートによって接続される アダプタは外界との糊の役⽬を果たす ドメインモデルはビジネスロジックを実⾏し、モデルの外側 についての知識を持たない
  69. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サンプルアーキテクチャ AWS Cloud Amazon API Gateway AWS Lambda Amazon DynamoDB User Internet
  70. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメインモデル、ポート、アダプターの構成 API Gateway Lambda関数 ドメインモデル Lambdaサービス アダプター アプリケーションサービス(ポート) アプリケーションサービス(ポート) アダプター アダプター アダプター データソースの 呼び出し
  71. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメインモデルクラス import { AuctionItem } from "./auction_item"; export class Auction { private auction_id: number; private auction_name: string; private auction_items: AuctionItem[]; // .... more members constructor(name: string, ...) { this.auction_name = name; //...initializing code } addAuctionItem(item: AuctionItem) { this.auction_items.push(item); //...more code } ドメインモデルで定義されたピュアなビジネス ロジックのみが実装される。 外部の世界に対する知識を持たない。
  72. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ポートクラス(アプリケーションサービス) import { Auction } from "./auction"; import { AuctionItem } from "./auction_item"; import { IAuctionAdapter } from "./i_auction_adapter"; import { IAuctionController } from "./i_auction_controller"; export class AuctionController implements IAuctionController { private auction: Auction; private auction_adapter: IAuctionAdapter; //... constructor(auction: Auction, auction_adapter: IAuctionAdapter) { this.auction = auction; this.auction_adapter = auction_adapter; //... } add_auction_items(items: AuctionItem[]) { //... ポートクラスがドメインモデルとアダプターの インスタンスを受け取り、ドメインモデルとア ダプターを呼び出す。
  73. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. アダプタクラス import { Auction } from "./auction"; import { IAuctionAdapter } from "./i_auction_adapter"; export class AuctionAdapter implements IAuctionAdapter { store_auction(auction: Auction) { //ドメインモデルの永続化 //... } } アダプタークラスは外部サービスとの連携を担当 単体テスト時はダミークラスに差し替えてテストを 実⾏
  74. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 依存関係 <Domain Model> Auction <Port> AuctionController <Adapter> AuctionDBAdapter <interface> IAuctionAdapter <Adapter> DummyAdapter
  75. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambdaサービスが ハンドラへのアダプタを提供 • アダプタの役割は外部からのリクエストを内部アプリケーションに 伝えるための変換を⾏うこと • API Gatewayからの呼び出し(REST API)をポートクラスの 呼び出しに変換する役割はLambdaランタイムが⾏なっている
  76. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 参考︓ヘキサゴナルアーキテクチャのサンプルコード • ヘキサゴナルアーキテクチャを利⽤したLambda関数のドメインモデルの実装 Live § 動画︓ https://www.youtube.com/watch?v=whQ-P05QeDQ § 資料︓ https://pages.awscloud.com/rs/112-TZM-766/images/DEV- 09_LiveCoding_with_hexagonal_architecture.pdf • ヘキサゴナルアーキテクチャを利⽤した AWS Lambda のドメインモデル オブジェクトサンプルコード https://github.com/aws-samples/aws-lambda-domain-model-sample
  77. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 参考︓ドメインモデルのトリレンマ • Domain model purity vs. domain model completeness (DDD Trilemma) https://enterprisecraftsmanship.com/posts/domain-model-purity- completeness/ • ドメインモデルの純粋性と完全性と性能のすべてを取ることはできない • アーキテクチャは常に選択が必要 • 純粋性と性能を選択する場合は、アプリケーションサービス層にドメインの知識 が⼀部漏れ出すことを許容する必要がある
  78. © 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. まとめ
  79. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. まとめ • 変化に迅速に対応し続けるためにアーキテクチャを選択する • マイクロサービスに適した組織に変更する • Event Stormingはビジネスイベントによって境界を⾒出す⼿法 • ビジネスドメインに従ってサブドメインをサービスに分割する • ⾮機能要件を適⽤するために論理アーキテクチャにマップする • ストラングラーパターンで段階的に移⾏する • ドメインモデルはピュアなビジネスロジックなのでTDDで実装する • ドメインモデルから外部へのアクセスを⾏うコードを分離する
  80. © 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. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Atsushi Fukui Senior Solutions Architect, Developer Specialist – DevAx Amazon Web Services Japan
  81. © 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. Appendix
  82. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サブドメインのタイプ High Low High Low ビジネスロジックの 複雑度 ビジネスにおける差別化 汎⽤ コア 汎⽤/ ⽀援 ⽀援
  83. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サブドメインの⽐較 サブドメイン タイプ 競合優位性 複雑度 変動性 実装 課題 コア あり ⾼ ⾼ 内製 関⼼事 汎⽤ なし ⾼ 低 購買/適⽤ 解決済み ⽀援 なし 低 低 内製/外注 明確
  84. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. サンプル – オークションシステム オークション <コア> ユーザー認証 <汎⽤> ⽀払い <⽀援> 出荷 <⽀援> 在庫 <⽀援> 通知 <汎⽤>
  85. © 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. コンテキストマッピングのパターン
  86. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. コンテキストマップ Sales context Support context Marketing context DDDでは境界づけられたコンテキストを統合 するための7つのパターンを紹介 • 共有カーネル (Shared Kernel) • 顧客/供給者の開発チーム (Customer/Supplier Development Teams) • 順応者 (Conformist) • 腐敗防⽌層 (Anticorruption layer) • 別々の道 (Separate ways) • 公開ホストサービス (Open/Host service) • 公表された⾔語 (Published language)
  87. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 共有カーネル • 2つ以上の境界づけられたコンテキストが ⼩さな/共通のモデルを共有 • 共有モデルの変更は⼀⽅の境界づけられ たコンテキストに直接影響する • Linkedライブラリとして実装可能 • 調整による複製 • 同⼀チームが実装する場合は、良い境界 づけられたコンテキストの統合⼿段 • 密結合 Bounded Context 1 Bounded Context 2
  88. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 顧客/供給者 • 供給者(上流)が顧客(下流)が必要とする ものを提供 • 供給者は顧客が受け取るものと時期を決定する Bounded Context 1 Bounded Context 2 U D
  89. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 順応者 • 上流は下流をサポートするモチベーションはない • 下流は上流のモデルに順応する Bounded Context 1 Bounded Context 2 U D
  90. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 腐敗防⽌層(Anti-Corruption Layer: ACL) • 最も防御的なコンテキストマッピングの関連 • 上流のモデルを下流のモデルに変換するレイヤ を作成 • コストが⾼くつき過ぎる可能性もある Bounded Context 1 Bounded Context 2 U D ACL
  91. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 公開ホストサービス(Open Host Service: OHS) • 境界づけられたコンテキストが他から利⽤可能 なプロトコルやインターフェイスを提供 • ⼤抵はAPIとして実装される • 他のタイプよりも容易に利⽤可能 Bounded Context 1 Bounded Context 2 OHS
  92. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 公表された⾔語(Published Language: PL) • 広く⽂書化された情報交換⾔語 • 多くの購読者からの購読を単純化 • XMLやJSONスキーマで定義が可能、 またはより最適化された記述フォーマット (Protobuf やAvro) • しばしば公開ホストサービスと共に⾒られる Bounded Context 1 Bounded Context 2 PL
  93. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 別々の道 • 境界づけられたコンテキスト感で関連を持たない • チームは⾃分達独⾃のソリューションを開発 Bounded Context 1 Bounded Context 2
  94. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. コンテキストマッピングの例 • 上流は公開ホストサービスと公表された⾔語 (REST API、JSON)を提供 • 下流は腐敗防⽌層を作成し、上流もモデルを ⾃分達のモデルに変換 ユーザー認証 コンテキスト オークション コンテキスト PL / OHS ACL REST (JSON) U D
  95. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. オークションシステムの例 オークション <コア> ユーザー認証 <汎⽤> ⽀払い <⽀援> 配送 <⽀援> 在庫 <⽀援> 通知 <汎⽤> OHS/PL OHS/PL U D ACL ACL U D U D U D
  96. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. ドメインイベント • 境界づけられたコンテキストのビジネス上の重要な出来事を記録 • コンテキスト内や他の境界づけられたコンテキストによって消費される(直接またはメッセージ ミドルウェアを通じて) • 疎結合、⾼凝集、および独⽴したデプロイ能⼒を推進 境界づけられた コンテキスト 境界づけられた コンテキスト ドメインイベント ドメインイベント 集約 メッセージミドルウェア 集約
  97. © 2023, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 例 – ドメインイベント オークション オークション 集約 Auction Created Bidder Registered Auction Started Auction Bidden Auction Completed 通知 消費
  98. © 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. Thank you! © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. Atsushi Fukui Senior Solutions Architect, Developer Specialist – DevAx Amazon Web Services Japan