mirror of
https://github.com/DocsHome/microservices.git
synced 2025-12-08 19:25:13 +00:00
update title and used relative path
This commit is contained in:
parent
f0633d7592
commit
bac4a94c98
@ -1,8 +1,8 @@
|
||||
# 5、事件驱动数据管理
|
||||
本书主要介绍如何使用微服务构建应用程序,这是本书的第五章。第一章介绍了微服务架构模式,讨论了使用微服务的优点与缺点。第二和第三章描述了微服务架构内的通信方式对比。第四章探讨了与服务发现相关的内容。在本章中,我们稍微做了点调整,研究微服务架构中出现的分布式数据管理问题。
|
||||
本书主要介绍如何使用微服务构建应用程序,这是本书的第五章。[第一章](1-introduction-to-microservices.md)介绍了微服务架构模式,讨论了使用微服务的优点与缺点。[第二](2-using-an-api-gateway.md)和[第三章](3-inter-process-communication.md)描述了微服务架构内的通信方式对比。第四章探讨了与服务发现相关的内容。在本章中,我们稍微做了点调整,研究微服务架构中出现的分布式数据管理问题。
|
||||
|
||||
## 4.1、微服务和分布式数据管理问题
|
||||
单体应用程序通常具有一个单一的关系型数据库。使用关系型数据库的一个主要优点是您的应用程序可以使用 ACID 事务,这些事务提供了以下重要保障:
|
||||
## 5.1、微服务和分布式数据管理问题
|
||||
单体应用程序通常具有一个单一的关系型数据库。使用关系型数据库的一个主要优点是您的应用程序可以使用 [ACID 事务](https://en.wikipedia.org/wiki/ACID),这些事务提供了以下重要保障:
|
||||
|
||||
- **原子性(Atomicity)** - 所作出的改变都是不可分割的原子操作
|
||||
- **一致性(Consistency)** - 数据库的状态始终保持一致
|
||||
@ -13,9 +13,9 @@
|
||||
|
||||
使用关系数据库的另一大好处是它提供了 SQL,这是一种丰富的、声明性的和标准化的查询语言。您可以轻松地编写一个查询来组合来自多个表的数据,之后 RDBMS 查询计划程序确定执行查询的最佳方式。您不必担心如何访问数据库等底层细节。因为你所有的应用程序数据都存放在同个数据库中,所以很容易查询。
|
||||
|
||||
很不幸的是,当我们转向微服务架构时,数据访问将变得非常复杂。这是因为每个微服务所拥有的数据对当前微服务来说是私有的,只能通过其提供的 API 进行访问。封装数据可确保微服务松散耦合,独立演化。如果多个服务访问相同的数据,模式(schema)更新需要对所有服务进行耗时、协调的更新。
|
||||
很不幸的是,当我们转向微服务架构时,数据访问将变得非常复杂。这是因为每个微服务所拥有的数据[对当前微服务来说是私有的](http://microservices.io/patterns/data/database-per-service.html),只能通过其提供的 API 进行访问。封装数据可确保微服务松散耦合,独立演化。如果多个服务访问相同的数据,模式(schema)更新需要对所有服务进行耗时、协调的更新。
|
||||
|
||||
更糟糕的是,不同的微服务经常使用不同类型的数据库。现代应用程序存储和处理着各种数据,而关系型数据库并不总是最佳选择。在某些场景,特定的 NoSQL 数据库可能具有更方便的数据模型,提供了更好的性能和可扩展性。例如,存储和查询文本服务使用文本搜索引擎(如 Elasticsearch)是合理的。类似地,存储社交图数据的服务应该可以使用图数据库,例如 Neo4j。因此,基于微服务的应用程序通常混合使用 SQL 和 NoSQL 数据库,即所谓的混合持久化(polyglot persistence)方法。
|
||||
更糟糕的是,不同的微服务经常使用不同类型的数据库。现代应用程序存储和处理着各种数据,而关系型数据库并不总是最佳选择。在某些场景,特定的 NoSQL 数据库可能具有更方便的数据模型,提供了更好的性能和可扩展性。例如,存储和查询文本服务使用文本搜索引擎(如 Elasticsearch)是合理的。类似地,存储社交图数据的服务应该可以使用图数据库,例如 Neo4j。因此,基于微服务的应用程序通常混合使用 SQL 和 NoSQL 数据库,即所谓的[混合持久化](http://martinfowler.com/bliki/PolyglotPersistence.html)(polyglot persistence)方法。
|
||||
|
||||
一个分区的数据存储混合持久化架构具有许多优点,包括了松散耦合的服务以及更好的性能与可扩展性。然而,它也引入了一些分布式数据管理方面的挑战。
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||

|
||||
|
||||
Order Service 无法直接访问 CUSTOMER 表。它只能使用客户服务提供的 API。订单服务可能使用了分布式事务,也称为两阶段提交(2PC)。然而,2PC 在现代应用中通常是不可行的。CAP 定理要求您在可用性与 ACID 式一致性之间作出选择,可用性通常是更好的选择。此外,许多现代技术,如大多数 NoSQL 数据库,都不支持 2PC。维护服务和数据库之间的数据一致性至关重要,因此我们需要另一种解决方案。
|
||||
Order Service 无法直接访问 CUSTOMER 表。它只能使用客户服务提供的 API。订单服务可能使用了[分布式事务](https://en.wikipedia.org/wiki/Two-phase_commit_protocol),也称为两阶段提交(2PC)。然而,2PC 在现代应用中通常是不可行的。[CAP 定理](https://en.wikipedia.org/wiki/CAP_theorem)要求您在可用性与 ACID 式一致性之间作出选择,可用性通常是更好的选择。此外,许多现代技术,如大多数 NoSQL 数据库,都不支持 2PC。维护服务和数据库之间的数据一致性至关重要,因此我们需要另一种解决方案。
|
||||
|
||||
第二个挑战是如何实现从多个服务中检索数据。例如,我们假设应用程序需要显示一个客户和他最近的订单。如果订单服务提供了用于检索客户订单的 API,那么您可以使用应用程序端连接以检索数据。应用程序从客户服务中检索客户,并从订单服务中检索客户的订单。但是,假设订单服务仅支持通过主键查找订单(也许它使用了仅支持基于主键检索的 NoSQL 数据库)。在这种情况下,没有有效的方法来检索所需的数据。
|
||||
|
||||
|
||||
94
README.md
94
README.md
@ -1,60 +1,60 @@
|
||||
# 《微服务:从设计到部署》中文版
|
||||
本仓库为电子书 [Designing and Deploying Microservices](https://www.nginx.com/resources/library/designing-deploying-microservices/) 的中文翻译版本,不涉及任何商业利益,纯属个人爱好。
|
||||
|
||||

|
||||

|
||||
|
||||
## 目录
|
||||
|
||||
### [0、前言](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/0-foreword.md)
|
||||
### [0、前言](0-foreword.md)
|
||||
|
||||
### [1、微服务简介](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#1微服务简介)
|
||||
- [1.1、构建单体应用](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#11构建单体应用)
|
||||
- [1.2、走向单体地狱](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#12走向单体地狱)
|
||||
- [1.3、微服务-解决复杂问题](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#13微服务-解决复杂问题)
|
||||
- [1.4、微服务的优点](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#14微服务的优点)
|
||||
- [1.5、微服务的缺点](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#15微服务的缺点)
|
||||
- [1.6、总结](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#16总结)
|
||||
- [微服务实战:NGINX Plus 作为反向代理服务器](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/1-introduction-to-microservices.md#微服务实战nginx-plus-作为反向代理服务器)
|
||||
### [1、微服务简介](1-introduction-to-microservices.md#1微服务简介)
|
||||
- [1.1、构建单体应用](1-introduction-to-microservices.md#11构建单体应用)
|
||||
- [1.2、走向单体地狱](1-introduction-to-microservices.md#12走向单体地狱)
|
||||
- [1.3、微服务-解决复杂问题](1-introduction-to-microservices.md#13微服务-解决复杂问题)
|
||||
- [1.4、微服务的优点](1-introduction-to-microservices.md#14微服务的优点)
|
||||
- [1.5、微服务的缺点](1-introduction-to-microservices.md#15微服务的缺点)
|
||||
- [1.6、总结](1-introduction-to-microservices.md#16总结)
|
||||
- [微服务实战:NGINX Plus 作为反向代理服务器](1-introduction-to-microservices.md#微服务实战nginx-plus-作为反向代理服务器)
|
||||
|
||||
### [2、使用 API 网关](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md)
|
||||
- [2.1、简介](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#21简介)
|
||||
- [2.2、客户端与微服务直接通信](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#22客户端与微服务直接通信)
|
||||
- [2.3、使用 API 网关](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#23使用API网关)
|
||||
- [2.4、API 网关的优点和缺点](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#24API网关的优点和缺点)
|
||||
- [2.5、实施 API 网关](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#25实施API网关)
|
||||
- [2.5.1、性能与扩展](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#251性能与扩展)
|
||||
- [2.5.2、使用响应式编程模型](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#252使用响应式编程模型)
|
||||
- [2.5.3、服务调用](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#253服务调用)
|
||||
- [2.5.4、服务发现](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#254服务发现)
|
||||
- [2.5.5、处理局部故障](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#255处理局部故障)
|
||||
- [2.6、总结](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#26总结)
|
||||
- [微服务实战:NGINX Plus 作为 API 网关](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/2-using-an-api-gateway.md#微服务实战nginx-plus-作为-api-网关)
|
||||
### [2、使用 API 网关](2-using-an-api-gateway.md)
|
||||
- [2.1、简介](2-using-an-api-gateway.md#21简介)
|
||||
- [2.2、客户端与微服务直接通信](2-using-an-api-gateway.md#22客户端与微服务直接通信)
|
||||
- [2.3、使用 API 网关](2-using-an-api-gateway.md#23使用API网关)
|
||||
- [2.4、API 网关的优点和缺点](2-using-an-api-gateway.md#24API网关的优点和缺点)
|
||||
- [2.5、实施 API 网关](2-using-an-api-gateway.md#25实施API网关)
|
||||
- [2.5.1、性能与扩展](2-using-an-api-gateway.md#251性能与扩展)
|
||||
- [2.5.2、使用响应式编程模型](2-using-an-api-gateway.md#252使用响应式编程模型)
|
||||
- [2.5.3、服务调用](2-using-an-api-gateway.md#253服务调用)
|
||||
- [2.5.4、服务发现](2-using-an-api-gateway.md#254服务发现)
|
||||
- [2.5.5、处理局部故障](2-using-an-api-gateway.md#255处理局部故障)
|
||||
- [2.6、总结](2-using-an-api-gateway.md#26总结)
|
||||
- [微服务实战:NGINX Plus 作为 API 网关](2-using-an-api-gateway.md#微服务实战nginx-plus-作为-api-网关)
|
||||
|
||||
### [3、进程间通信](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md)
|
||||
- [3.1、简介](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#31简介)
|
||||
- [3.2、交互方式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#32交互方式)
|
||||
- [3.3、定义 API](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#33定义api)
|
||||
- [3.4、演化 API](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#34演化api)
|
||||
- [3.5、处理局部故障](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#35处理局部故障)
|
||||
- [3.6、IPC 技术](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#36ipc-技术)
|
||||
- [3.7、异步、基于消息的通信](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#37异步基于消息的通信)
|
||||
- [3.8、同步的请求/响应 IPC](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#38同步的请求响应ipc)
|
||||
- [3.8.1、REST](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#381rest)
|
||||
- [3.8.2、Thrift](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#382thrift)
|
||||
- [3.9、消息格式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#39消息格式)
|
||||
- [3.10、总结](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#310总结)
|
||||
- [微服务实战:NGINX 与应用程序架构](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/3-inter-process-communication.md#微服务实战nginx-与应用程序架构)
|
||||
### [3、进程间通信](3-inter-process-communication.md)
|
||||
- [3.1、简介](3-inter-process-communication.md#31简介)
|
||||
- [3.2、交互方式](3-inter-process-communication.md#32交互方式)
|
||||
- [3.3、定义 API](3-inter-process-communication.md#33定义api)
|
||||
- [3.4、演化 API](3-inter-process-communication.md#34演化api)
|
||||
- [3.5、处理局部故障](3-inter-process-communication.md#35处理局部故障)
|
||||
- [3.6、IPC 技术](3-inter-process-communication.md#36ipc-技术)
|
||||
- [3.7、异步、基于消息的通信](3-inter-process-communication.md#37异步基于消息的通信)
|
||||
- [3.8、同步的请求/响应 IPC](3-inter-process-communication.md#38同步的请求响应ipc)
|
||||
- [3.8.1、REST](3-inter-process-communication.md#381rest)
|
||||
- [3.8.2、Thrift](3-inter-process-communication.md#382thrift)
|
||||
- [3.9、消息格式](3-inter-process-communication.md#39消息格式)
|
||||
- [3.10、总结](3-inter-process-communication.md#310总结)
|
||||
- [微服务实战:NGINX 与应用程序架构](3-inter-process-communication.md#微服务实战nginx-与应用程序架构)
|
||||
|
||||
### [4、服务发现](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md)
|
||||
- [4.1、为何使用服务发现](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#41为何使用服务发现)
|
||||
- [4.2、客户端发现模式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#42客户端发现模式)
|
||||
- [4.3、服务端发现模式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#43服务端发现模式)
|
||||
- [4.4、服务注册中心](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#44服务注册中心)
|
||||
- [4.5、服务注册方式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#45服务注册方式)
|
||||
- [4.6、自注册模式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#46自注册模式)
|
||||
- [4.7、第三方注册模式](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#47第三方注册模式)
|
||||
- [4.8、总结](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#48总结)
|
||||
- [微服务实战:NGINX 的灵活性](https://github.com/oopsguy/microservices-from-design-to-deployment-chinese/blob/master/4-service-discovery.md#微服务实战nginx-的灵活性)
|
||||
### [4、服务发现](4-service-discovery.md)
|
||||
- [4.1、为何使用服务发现](4-service-discovery.md#41为何使用服务发现)
|
||||
- [4.2、客户端发现模式](4-service-discovery.md#42客户端发现模式)
|
||||
- [4.3、服务端发现模式](4-service-discovery.md#43服务端发现模式)
|
||||
- [4.4、服务注册中心](4-service-discovery.md#44服务注册中心)
|
||||
- [4.5、服务注册方式](4-service-discovery.md#45服务注册方式)
|
||||
- [4.6、自注册模式](4-service-discovery.md#46自注册模式)
|
||||
- [4.7、第三方注册模式](4-service-discovery.md#47第三方注册模式)
|
||||
- [4.8、总结](4-service-discovery.md#48总结)
|
||||
- [微服务实战:NGINX 的灵活性](4-service-discovery.md#微服务实战nginx-的灵活性)
|
||||
|
||||
### [5、事件驱动数据管理](5-event-driven-data-management-for-microservices.md)
|
||||
- [5.1、微服务与分布式数据管理问题](5-event-driven-data-management-for-microservices.md#51微服务与分布式数据管理问题)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user