性能維持 スケーラビリティ 学べる教訓 コマンドとクエリ毎に専用DBを選定 コマンドモデルは整合性を重視したトランザクション向きDBを選定 クエリモデルは高速な読み取り・集計に特化したDBを選定 要件を満たせる場合は、コマンドとクエリで同じDBを選定 コマンドクエリ分離によるスケーラビリティの向上 "The code used is good, as evidenced by a consistent response time as the number of users and use of the CPU service increases. [...] The read and write processes can run in parallel safely." CQRS Pattern Success Story (D. Husni Fahri Rizal, 2020) 決済にイベントソーシングを適用 成功ポイント 真実の源泉 (ソース・オブ・トゥルース) の確立 すべての状態変更を不変のイベントログに記録 完全な監査証跡による事後検証と状態再現の容易さ 監査対応 トレーサビリティ 状態再現 学べる教訓 状態変更の履歴性が重要な領域での有効性 支払いやサブスクリプション管理など、履歴が重要な領域での選定 再構築前提の設計で開発速度が向上 "Even if something turns out to be wrong because of a bug we can fix it and rebuild the conclusion based on the data we have." The beautiful headache called event sourcing (Maurice Haak, Jaap Taal, 2020)
過剰設計 コスト増 不要な複雑性 学べる教訓 適用領域を慎重に選定する 複数書き込み者がいるか否かが判断基準の1つ 「first-one-wins、last-one-wins」のシナリオが存在する場合に検討 採用前にコマンドとクエリの要件を洗い出し、過剰設計にならないか判 断した方が良い "So, when should you avoid CQRS? The answer is most of the time." When to avoid CQRS (Udi Dahan, 2011) イベントソーシングモノリス化 失敗ポイント システム全体をESに基づいて、単一のイベントストアに構築 機能単位やサービス単位での個別のスケールアウトが難しい 全ての機能が単一のイベントストアに依存しているため、変更や障害に 弱い モノリス化 複雑性増大 メンテナンス困難 学べる教訓 特定のドメインにのみ選択的に適用する CQRS/ESはトップレベルのアーキテクチャではない ドメイン毎に専用のイベントストアを用意する方針も選択肢の1つ "The single biggest bad thing that Young has seen during the last ten years is the common anti-pattern of building a whole system based on Event sourcing." A Whole System Based on Event Sourcing is an Anti-Pattern (Jan Stenberg, 2016)