--- url: "http://microservices.io/patterns/cn/decomposition/decompose-by-subdomain.html" titulek: "Decompose by subdomain" h1: "Pattern: Decompose by subdomain" popis: "" jazyk: "" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 21:11:32" znaku: 8158 slov: 694 kodovani: "iso-8859-2" sha256: "3cb9ffbe48439f6cf38c560886c5430d3f89600822a6d1767a658197c5ae5290" --- #### [Chris Richardson 的微服务架构网站](/index.html) **本站由[Kong](https://konghq.com/)提供支持** #### 微服务架构咨询和培训服务 本站点由 Chris Richardson 编写和维护,他是经典技术著作《POJOS IN ACTION》一书的作者,也是 cloudfoundry.com 最初的创始人。Chris çš„ç ”çŠśé˘†ĺŸŸĺŒ…ć‹Ź Spring、Scala、微服务架构设计、领域驱动设计、NoSQL 数据库、分布式数据管理、事件驱动的应用编程等。Chris 是一位连续创业者,[eventuate.io](http://eventuate.io) 是他的最新创业项目,一个微服务应用和数据服务平台。 Chris 定期为企业提供微服务设计培训和实战项目的架构咨询服务。近年来 Chris 多次访问中国,为包括华为、SAPă€ćƒ ć™Žă€ä¸œéŁŽćą˝č˝Śç­‰ĺ¤§ĺž‹äźä¸šćäž›ĺžŽćœĺŠĄćžśćž„ç›¸ĺ…łçš„ćŠ€ćœŻĺ’¨čŻ˘ćœĺŠĄă€‚ĺŚ‚ć‚¨ĺ¸Œćœ›ä¸Ž Chris 深入交流,建立合作,请点击下方按钮跟他取得联系。 [预约课程](http://www.chrisrichardson.net/contactus.html) #### ĺžŽćœĺŠĄĺş”ç”¨çš„ç¤şäž‹äťŁç  为了避免纸上谈兵,Chris ćäž›äş†ä¸€ĺĽ—ä¸Žčż™äş›ć¨Ąĺźç›¸ĺ…łçš„ç¤şäž‹äťŁç ă€‚čż™çť„äťŁç ä˝żç”¨[eventuate](http://eventuate.io)框架,实现了微服务架构下分布式数据的存取。请点击下方按钮访问。 [čŽżé—ŽäťŁç ](http://eventuate.io/exampleapps.html) --- ### 模式库 ć ¸ĺżƒć¨Ąĺź - [单体架构](/patterns/cn/monolithic.html) - [微服务架构](/patterns/cn/microservices.html) 服务拆分 - [ć šćŽä¸šĺŠĄčƒ˝ĺŠ›ć‹†ĺˆ†](/patterns/cn/decomposition/decompose-by-business-capability.html) new - [ć šćŽé˘†ĺŸŸçš„ĺ­ĺŸŸć‹†ĺˆ†](/patterns/cn/decomposition/decompose-by-subdomain.html) new 部署模式 - [单主机上部署服务的多个实例](/patterns/cn/deployment/multiple-services-per-host.html) - [单主机上部署服务的单个实例](/patterns/cn/deployment/single-service-per-host.html) - [服务实例与虚拟机一一对应](/patterns/cn/deployment/service-per-vm.html) - [服务实例与容器一一对应](/patterns/cn/deployment/service-per-container.html) - [ć— ćœĺŠĄĺ™¨éƒ¨ç˝˛](/patterns/cn/deployment/serverless-deployment.html) - [服务部署平台](/patterns/cn/deployment/service-deployment-platform.html) new 需要关注的边界问题 - [微服务的基底](/patterns/cn/microservice-chassis.html) - [配置信息外部化](/patterns/cn/externalized-configuration.html) new 通讯模式 - [远程过程调用](/patterns/cn/communication-style/rpi.html) - [月息](/patterns/cn/communication-style/messaging.html) - [领域独用协议](/patterns/cn/communication-style/domain-specific.html) new - [API 网关](/patterns/cn/apigateway.html) - [服务前端的后端](/patterns/cn/apigateway.html) - [客户端服务发现](/patterns/cn/client-side-discovery.html) - [服务器端服务发现](/patterns/cn/server-side-discovery.html) - [服务注册表](/patterns/cn/service-registry.html) - [自注册](/patterns/cn/self-registration.html) - [第三方注册](/patterns/cn/3rd-party-registration.html) - [断路器](/patterns/cn/reliability/circuit-breaker.html) new 数据管理 - [每服务数据库](/patterns/cn/data/database-per-service.html) - [共享数据库](/patterns/cn/data/shared-database.html) - [事件驱动架构](/patterns/cn/data/event-driven-architecture.html) - [事件溯源](/patterns/cn/data/event-sourcing.html) - [CQRS](/patterns/cn/data/cqrs.html) - [事务日志跟踪](/patterns/cn/data/transaction-log-tailing.html) - [数据库触发器](/patterns/cn/data/database-triggers.html) - [应用程序事件](/patterns/cn/data/transactional-outbox.html) 安全模式 - [访问令牌](/patterns/cn/security/access-token.html) new 可测试性 - [服务组件测试](/patterns/cn/testing/service-component-test.html) new - [服务集成协议测试](/patterns/cn/testing/service-integration-contract-test.html) new 可观测性 - [应用日志](/patterns/cn/observability/application-logging.html) new - [ĺş”ç”¨ćŒ‡ć ‡](/patterns/cn/observability/application-metrics.html) new - [审计日志](/patterns/cn/observability/audit-logging.html) new - [分布式追踪](/patterns/cn/observability/distributed-tracing.html) new - [异常追踪](/patterns/cn/observability/exception-tracking.html) new - [健康检查](/patterns/cn/observability/health-check-api.html) new UI 模式 - [ćœĺŠĄĺ™¨çŤŻéĄľé˘ç˘Žç‰‡ĺŒ–ĺ…ƒç´ ćž„ĺťş](/patterns/cn/ui/server-side-page-fragment-composition.html) new - [厢戡獯 UI 构建](/patterns/cn/ui/client-side-ui-composition.html) new --- [订阅微服务邮件列表](http://visitor.r20.constantcontact.com/d.jsp?llr=ula8akwab&p=oi&m=1123470377332&sit=l6ktajjkb&f=15d9bba9-b33d-491f-b874-73a41bba8a76) --- 全新的微服务应用支撑平台,成功解决微服务架构下分布式数据管理的难题。 [了解更多](http://eventuate.io/) ĺŠ ĺ…Ľ [微服务架构的 Google 讨论组](https://groups.google.com/forum/#!forum/microservices)(需要翻墙) # Pattern: Decompose by subdomain # Context You are developing a large, complex application and want to use the [microservice architecture](../microservices.html). The microservice architecture structures an application as a set of loosely coupled services. The goal of the microservice architecture is to accelerate software development by enabling continuous delivery/deployment. The microservice architecture does this in two ways: 1. Simplifies testing and enables components to deployed independently 2. Structures the engineering organization as a collection of small (6-10 members), autonomous teams, each of which is responsible for one or more services These benefits are not automatically guaranteed. Instead, they can only be achieved by the careful functional decomposition of the application into services. A service must be small enough to be developed by a small team and to be easily tested. A useful guideline from object-oriented design (OOD) is the Single Responsibility Principle ([SRP](http://www.objectmentor.com/resources/articles/srp.pdf)). The SRP defines a responsibility of a class as a reason to change, and states that a class should only have one reason to change. It make sense to apply the SRP to service design as well and design services that are cohesive and implement a small set of strongly related functions. The application also be decomposed in a way so that most new and changed requirements only affect a single service. That is because changes that affect multiple services requires coordination across multiple teams, which slows down development. Another useful principle from OOD is the Common Closure Principle (CCP), which states that classes that change for the same reason should be in the same package. Perhaps, for instance, two classes implement different aspects of the same business rule. The goal is that when that business rule changes developers, only need to change code in a small number - ideally only one - of packages. This kind of thinking makes sense when designing services since it will help ensure that each change should impact only one service. # Problem How to decompose an application into services? # Forces - The architecture must be stable - Services must be cohesive. A service should implement a small set of strongly related functions. - Services must conform to the Common Closure Principle - things that change together should be packaged together - to ensure that each change affect only one service - Services must be loosely coupled - each service as an API that encapsulates its implementation. The implementation can be changed without affecting clients - A service should be testable - Each service be small enough to be developed by a “two pizza” team, i.e. a team of 6-10 people - Each team that owns one or more services must be autonomous. A team must be able to develop and deploy their services with minimal collaboration with other teams. ## Solution Define services corresponding to domain-driven design subdomains - The [Decompose by business capability](decompose-by-business-capability.html) pattern is an alternative pattern --- Tweet [关注本站推特账号 @crichardson](https://twitter.com/crichardson) Š 2017 Chris Richardson 版权所有 • 保留一切权利 • 本站由 [Kong](https://konghq.com/) 提供支持.