设计微服务的过程

原文: https://microservices.io/post/architecture/2023/02/09/assemblage-architecture-definition-process.html

文章目录

  • [Overview of Assemblage](#Overview of Assemblage)
  • [Step 1: Discovering system operations](#Step 1: Discovering system operations)
  • [Step 2: Defining subdomains](#Step 2: Defining subdomains)
  • [Step 3: Designing services and their collaborations](#Step 3: Designing services and their collaborations)
  • [Step 4: Evaluating the microservice architecture](#Step 4: Evaluating the microservice architecture)
  • [Step 5: Refactoring the microservice architecture](#Step 5: Refactoring the microservice architecture)
  • [Where to go from here](#Where to go from here)

The essence of applying the Microservice architecture pattern is defining the service architecture: identifying the services, defining their responsibilities, their APIs and their collaborations (with other services). Choosing the right technical architecture - deployment platform, message broker, etc. - also matters. But that's a far easier and much less important task. That's because if you define your services incorrectly you will create a fragile, and difficult to maintain distributed monolith that can threaten your organization's very existence. And to make matters worse, defining the service architecture isn't just a matter of reading the manual. It's a design activity that involves numerous, and often tricky trade-offs.

I've written a lot about how the dark energy and dark matter forces can help define a service architeture. And, in a few talks, I've briefly described the architecture definition process, which is based on dark energy/matter, that I like to use. But until now, it's not something I've described in detail outside of my microservice architecture workshops. The goal of this article is to properly introduce my architecture definition process, which I've named Assemblage.

微服务的设计过程其实就是DDD的理念(subdomain & aggregates)+cloud native的技术(CI/CD)

Overview of Assemblage

The input to the architecture definition process consists of the application's requirements, e.g. user stories/scenarios, non-functional requirements, wireframes, etc. The output of the process is a service architecture, which consists of the services, and their responsibilities, APIs, and collaborations.

The architecture definition process consists of the following steps:

  • Discovering system operations
  • Defining subdomains
  • Designing services and their collaborations
  • Evaluating a microservice architecture
  • Refactoring a microservice architecture

这个过程不就是DDD的分析过程吗?不过忽略了aggregate的概念。基本上就是DDD的内容只不过用了不同的术语而已。DDD主要聚焦于业务逻辑的拆分,这里还兼顾了技术方面的实现。

Step 1: Discovering system operations

The first step of the process distills the requirements into a set of system operations. A system operation is an invokable behavior implemented by the application. For example, an e-commerce application would typically implement operations such as createCustomer(), createOrder(), cancelOrder() and findOrderHistory(). A system operation reads and/or writes one or more business entities, a.k.a. DDD aggregates, such as Customer and Order. The system operations model the application's black box behavior.

A system operation is technology independent. But the actual implementation will be invoked in one of several ways. It might, for example, be invoked by a HTTP request or a message. Alternatively, a system operation might be triggered by the passing of time, eg. a monthly batch job.

就是提炼出API & aggregates

Step 2: Defining subdomains

The second step of the process defines the subdomains. A subdomain is an implementable model of a sliver of business functionality, a.k.a. business capability. Each subdomain is owned by a small team. A subdomain consists of the aggregates acted upon by system operations. In Java application, for example, a subdomain would consist of Java classes.

把大的domain拆分成subdomain,确定每个subdomain的功能。注意,并不是把system operation简单的交给某个subdomain去实现,有可能一个system operation需要多个subdomain的配合实现,这时候可能就需要API gateway了。

Step 3: Designing services and their collaborations

The third step defines the service architecture by grouping the subdomains to form services and designing distributed system operations using the service collaboration (e.g. Saga, API Composition, and CQRS) patterns.

The dark energy and dark matter forces drive the definition of services and the design of system operations.

The output of the third step is a candidate service architecture that is either a monolithic architecture (i.e. a single service) or a microservice architecture (two or more services). The architecture documentation includes a microservice canvas for each service.

这个其实是第二步的延伸,既然确定了一个操作需要多个subdomain的合作,那么自然也需要确定他们是如何合作,包括同步API或者异步message, 甚至CQRS。

Step 4: Evaluating the microservice architecture

The fourth step evaluates the architecture to identify architectural issues/smells that are potential violations of the dark energy and dark matter forces.

Examples of architectural issues/smells include

Teams that lack of autonomy because too many teams work together on the same service

Services that repeatedly change in lock step due to design time coupling

Operation that have low availability and high latency because they span too many service and require too many network round trips

The output of fourth step is a list of potential architectural issues.

Step 5: Refactoring the microservice architecture

The fifth and final step refactors the architecture to eliminate architecture smells identified in the previous step. There are four levels of refactorings:

System operations - e.g. change collaboration patterns

Services - eg. move subdomains between services

Subdomains - e.g. split subdomains

System operation specifications - e.g. to reduce runtime coupling

The output of the fifth step is an improved microservice architecture.

4和5就是就是看自己设计的微服务架构是否合理, 什么是合理?主要是微服务要高内聚,松耦合。在获得微服务好处的时候,尽量减少微服务的依赖,避免微服务之间的复杂交互。

Where to go from here

This process defines the services, and their responsibilities, APIs, and collaborations. The next step is to define the technical architecture. A big part of defining the technical architecture is selecting and applying the application infrastructure and infrastructure patterns from the microservices pattern language, e.g. deployment, observability, inter-service communication, etc. That's a topic that I will describe in detail in future articles.

确定了微服务架构以后,就是一些技术实现的细节了,API gateway, CI/CD,CQRS等等

相关推荐
a2591748032-随心所记几秒前
android拆解super.img内容
android·linux·运维·服务器
豆瓣鸡1 分钟前
Agent实战练习
java·python·学习
实心儿儿10 分钟前
Linux —— 文件系统_路径解析_软硬连接
linux·运维·服务器
weisian15112 分钟前
Java并发编程--48-美团Leaf与百度UidGenerator:分布式ID生成器的工业级实践
java·leaf号段模式·leaf雪花模式·uidgenerator
沐风清扬13 分钟前
领域驱动设计 (DDD) 架构完全解析
微服务
郝开16 分钟前
Spring Cloud Gateway 3.5.14 使用手册
java·数据库·spring boot·gateway
云达闲人16 分钟前
搭建DevOps企业级仿真实验环境:004Proxmox 内核调优与虚拟化优化
linux·服务器·devops·硬件加速·linux内核调优·虚拟化优化·内存气球
摇滚侠20 分钟前
IDEA 中快捷键的使用和修改 IDEA 中如何调试程序
java·ide·intellij-idea
风筝在晴天搁浅26 分钟前
手撕单例模式
java·开发语言·单例模式
沐风清扬28 分钟前
复杂业务系统架构:CQRS 读写分离与 ES/RabbitMQ 基础指南
微服务·架构