マイクロサービスで DDD と CQRS パターンを使ってビジネスの複雑さに取り組むTackling Business Complexity in a Microservice with DDD and CQRS Patterns
ビジネス ドメインの理解を反映するマイクロソフトサービスまたはコンテキスト境界ごとのドメイン モデルを設計するDesign a domain model for each microservice or Bounded Context that reflects understanding of the business domain.
このセクションでは、複雑なサブシステムへの取り組みが必要な場合に実装する高度なマイクロサービスについて、またドメイン専門家の知識と絶えず変化するビジネス ルールに由来するマイクロサービスについて説明します。This section focuses on more advanced microservices that you implement when you need to tackle complex subsystems, or microservices derived from the knowledge of domain experts with ever-changing business rules. このセクションで使用するアーキテクチャ パターンは、図 9-1 に示すように、ドメイン駆動設計 (DDD: Domain-Driven Design) とコマンドクエリ責務分離 (CQRS: Command and Query Responsibility Segregation) の手法に基づいています。The architecture patterns used in this section are based on domain-driven design (DDD) and Command and Query Responsibility Segregation (CQRS) approaches, as illustrated in Figure 9-1.
図 9-1Figure 9-1. 外部マイクロサービス アーキテクチャとマイクロサービスごとの内部アーキテクチャ パターンとの対比External microservice architecture versus internal architecture patterns for each microservice
ただし、ASP.NET Core Web API サービスの実装方法や Swashbuckle による Swagger メタデータの公開方法など、データ駆動型マイクロサービスのテクニックのほとんどは、DDD パターンで内部的に実装される高度なマイクロサービスにも適用されます。However, most of the techniques for data driven microservices, such as how to implement an ASP.NET Core Web API service or how to expose Swagger metadata with Swashbuckle, are also applicable to the more advanced microservices implemented internally with DDD patterns. 前述した実施方法のほとんどはここでも、または任意の種類のマイクロ サービスにも適用されるため、このセクションは前のセクションの内容を増補するものとなっています。This section is an extension of the previous sections, because most of the practices explained earlier also apply here or for any kind of microservice.
このセクションでは、まず eShopOnContainers 参照アプリケーションで使用される簡略化された CQRS パターンの詳細を示します。This section first provides details on the simplified CQRS patterns used in the eShopOnContainers reference application. 後で DDD 手法の概要を説明しますが、そこでは、アプリケーションで再利用できる一般的なパターンを確認できます。Later, you will get an overview of the DDD techniques that enable you to find common patterns that you can reuse in your applications.
DDD は、学習用に豊富な技術資料が提供されている大きなテーマです。DDD is a large topic with a rich set of resources for learning. 入門書としては、Eric Evans 著の『Domain-Driven Design』 (ドメイン駆動設計)、さらに Vaughn Vernon、Jimmy Nilsson、Greg Young、Udi Dahan、Jimmy Bogard の各氏、およびその他多くの DDD/CQRS の専門家による技術資料などを利用できます。You can start with books like Domain-Driven Design by Eric Evans and additional materials from Vaughn Vernon, Jimmy Nilsson, Greg Young, Udi Dahan, Jimmy Bogard, and many other DDD/CQRS experts. ただし、DDD 手法の適用方法の習得には何より、具体的なビジネス ドメイン内で専門家との対話、ホワイトボードを使った議論、ドメイン モデリングのセッションを利用する試みが必要です。But most of all you need to try to learn how to apply DDD techniques from the conversations, whiteboarding, and domain modeling sessions with the experts in your concrete business domain.
その他の技術情報Additional resources
DDD (ドメイン駆動設計)DDD (Domain-Driven Design)
Eric Evans。Domain Language (ドメイン言語) http://domainlanguage.com/Eric Evans. Domain Language http://domainlanguage.com/
Martin Fowler。Domain-Driven Design (ドメイン駆動設計) http://martinfowler.com/tags/domain%20driven%20design.htmlMartin Fowler. Domain-Driven Design http://martinfowler.com/tags/domain%20driven%20design.html
Jimmy Bogard。Strengthening your domain: a primer (ドメインの強化: 入門) https://lostechies.com/jimmybogard/2010/02/04/strengthening-your-domain-a-primer/Jimmy Bogard. Strengthening your domain: a primer https://lostechies.com/jimmybogard/2010/02/04/strengthening-your-domain-a-primer/
DDD 関連の書籍DDD books
Eric Evans。Domain-Driven Design: Tackling Complexity in the Heart of Software (ドメイン駆動設計: ソフトウェアの核心にある複雑さに立ち向かう) https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/Eric Evans. Domain-Driven Design: Tackling Complexity in the Heart of Software https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/
Eric Evans。Domain-Driven Design Reference: Definitions and Pattern Summaries (ドメイン駆動設計リファレンス: 定義とパターンの概要) https://www.amazon.com/Domain-Driven-Design-Reference-Definitions-2014-09-22/dp/B01N8YB4ZO/Eric Evans. Domain-Driven Design Reference: Definitions and Pattern Summaries https://www.amazon.com/Domain-Driven-Design-Reference-Definitions-2014-09-22/dp/B01N8YB4ZO/
Vaughn Vernon。Implementing Domain-Driven Design (実践ドメイン駆動設計) https://www.amazon.com/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577/Vaughn Vernon. Implementing Domain-Driven Design https://www.amazon.com/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577/
Vaughn Vernon。Domain-Driven Design Distilled (ドメイン駆動設計の本質) https://www.amazon.com/Domain-Driven-Design-Distilled-Vaughn-Vernon/dp/0134434420/Vaughn Vernon. Domain-Driven Design Distilled https://www.amazon.com/Domain-Driven-Design-Distilled-Vaughn-Vernon/dp/0134434420/
Jimmy Nilsson。Applying Domain-Driven Design and Patterns (ドメイン駆動設計とパターンの適用) https://www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202/Jimmy Nilsson. Applying Domain-Driven Design and Patterns https://www.amazon.com/Applying-Domain-Driven-Design-Patterns-Examples/dp/0321268202/
Cesar de la Torre。N-Layered Domain-Oriented Architecture Guide with .NET (.NET を使用した N 層のドメイン指向アーキテクチャのガイド) https://www.amazon.com/N-Layered-Domain-Oriented-Architecture-Guide-NET/dp/8493903612/Cesar de la Torre. N-Layered Domain-Oriented Architecture Guide with .NET https://www.amazon.com/N-Layered-Domain-Oriented-Architecture-Guide-NET/dp/8493903612/
Abel Avram および Floyd Marinescu。Domain-Driven Design Quickly (ドメイン駆動設計の要点) https://www.amazon.com/Domain-Driven-Design-Quickly-Abel-Avram/dp/1411609255/Abel Avram and Floyd Marinescu. Domain-Driven Design Quickly https://www.amazon.com/Domain-Driven-Design-Quickly-Abel-Avram/dp/1411609255/
DDD に関するトレーニングDDD training
- Julie Lerman および Steve Smith。Domain-Driven Design Fundamentals (ドメイン駆動設計の基礎) http://bit.ly/PS-DDDJulie Lerman and Steve Smith. Domain-Driven Design Fundamentals http://bit.ly/PS-DDD