

# REL03-BP02 构建专注于特定业务领域和功能的服务
<a name="rel_service_architecture_business_domains"></a>

 面向服务的架构（SOA，Service-Oriented Architecture）采用由业务需求定义的划分明确的功能来构建服务。微服务则使用领域模型和有界上下文对此进行进一步限制，使每项服务都只用于一种用途。专注于特定功能让您可以区分不同服务的可靠性要求，并且更有针对性地锁定投资目标。简洁的业务问题和与每项服务关联的小型团队也简化了组织扩展。 

 在设计微服务架构时，借助于领域驱动设计 (DDD) 对使用实体的业务问题进行建模十分有帮助。以 Amazon.com 网站为例，实体可能包括包装、配送、时间表、价格、折扣和货币。然后，该模型会使用 [https://martinfowler.com/bliki/BoundedContext.html](https://martinfowler.com/bliki/BoundedContext.html)进一步细分为更小的模型，具有相似功能和属性的实体在边界上下文中被分到一组。因此，在 Amazon.com 例子中，包装、配送和时间表是装运上下文的一部分，而价格、折扣和货币是定价上下文的一部分。通过将模型细分为不同的上下文，即可得到如何确定微服务边界的模板。 

![\[如何确定微服务边界的模型模板\]](http://docs.aws.amazon.com/zh_cn/wellarchitected/2022-03-31/framework/images/building-services.png)


 **未建立这种最佳实践的情况下暴露的风险等级：** 高 

## 实施指导
<a name="implementation-guidance"></a>
+  根据业务领域及各自的功能设计工作负载。专注于特定功能让您可以区分不同服务的可靠性要求，并且更有针对性地锁定投资目标。简洁的业务问题和与每项服务关联的小型团队也简化了组织扩展。 
  +  执行领域分析，为您的工作负载制定领域驱动设计 (DDD) 方案。然后，您可以选择一个架构类型，以满足您的工作负载需求。
    +  [如何将整体式架构分解为多项微服务](https://martinfowler.com/articles/break-monolith-into-microservices.html) 
    +  [在被遗留系统包围时通过 DDD 开始着手](https://domainlanguage.com/wp-content/uploads/2016/04/GettingStartedWithDDDWhenSurroundedByLegacySystemsV1.pdf) 
    +  [Eric Evans“领域驱动设计：解决软件核心的复杂性”](https://www.amazon.com/gp/product/0321125215) 
    +  [在 AWS 上实施微服务](https://docs.aws.amazon.com/whitepapers/latest/microservices-on-aws/introduction.html) 
+ 将服务分解成尽可能小的组件。借助微服务架构，您可以将工作负载分解成功能最小的组件，以便支持组织的可扩展性和敏捷性。
  +  根据工作负载及其设计目标、限制和任何其他使用注意事项来定义 API。
    +  定义 API。
      +  API 定义应允许增加参数。 
    +  定义设计可用性。
      + 您的 API 可以具有针对不同功能的多个设计目标。
    +  设置限制 
      +  通过测试来确定工作负载的功能限制。

## 资源
<a name="resources"></a>

 **相关文档：** 
+  [Amazon API Gateway：使用 OpenAPI 配置 REST API](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-import-api.html) 
+  [边界上下文（领域驱动设计的中心模式）](https://martinfowler.com/bliki/BoundedContext.html) 
+  [Eric Evans“领域驱动设计：解决软件核心的复杂性”](https://www.amazon.com/gp/product/0321125215) 
+  [在被遗留系统包围时通过 DDD 开始着手](https://domainlanguage.com/wp-content/uploads/2016/04/GettingStartedWithDDDWhenSurroundedByLegacySystemsV1.pdf) 
+  [如何将整体式架构分解为多项微服务](https://martinfowler.com/articles/break-monolith-into-microservices.html) 
+  [在 AWS 上实施微服务](https://docs.aws.amazon.com/whitepapers/latest/microservices-on-aws/introduction.html) 
+  [微服务利弊权衡](https://martinfowler.com/articles/microservice-trade-offs.html) 
+  [微服务 – 一个全新架构术语的定义](https://www.martinfowler.com/articles/microservices.html) 
+  [AWS 上的微服务](https://aws.amazon.com/microservices/) 