Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df4699c
commit bc017f5
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
- [概览](./微服务.md) | ||
- [服务建模](./服务建模.md) | ||
- [集成](./集成.md) | ||
- [集成](./集成.md) | ||
- [分解单块系统](./分解单块系统.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 分解单块系统 | ||
|
||
## 下手处 | ||
|
||
根据改变速度,团队结构,安全需求以及实现技术等对其进行分离 | ||
|
||
## 依赖处理 | ||
|
||
### 数据库 | ||
|
||
- 分析数据库表的依赖关系,把不同的表或者不同的数据分到不同的限界上下文里 | ||
|
||
#### 外键 | ||
|
||
放弃,改用api调用来实现数据查询 | ||
|
||
#### 共享数据 | ||
|
||
- 静态数据 | ||
|
||
如果要求不苛刻,可以使用配置文件,否则使用一个专门的服务器来管理静态数据 | ||
|
||
- 动态数据 | ||
|
||
独立出一个服务,专门来处理 | ||
|
||
- 共享表 | ||
|
||
需要重新审视设计,进行分表操作 | ||
|
||
### 数据库重构 | ||
|
||
先分离数据库再分离服务,虽然这样会破坏事务完整性,但是可以保证随时可以回退 | ||
|
||
### 事务 | ||
|
||
分离数据库之后,如何保证事务的安全性? | ||
|
||
如果一个事务中的部分操作成功,部分操作失败,该如何? | ||
|
||
- 再试一次 | ||
- 也就是最终一致性,如果失败了,将其放入队列,稍后重试 | ||
- 终止操作 | ||
- 发起一个补偿事务,来撤销成功的操作 | ||
- 但是如果补偿事务再失败的话,可以引入重试或者人工操作 | ||
- 分布式事务 | ||
- 也就是两阶段提交,每个事务参与者需要向事务管理器投票,如果所有参与者都同意,则事务管理器告诉所有参与者提交,否则只要有一个不同意,则所有事务参与者都有放弃此次事务 | ||
|
||
引入这些都会增加系统的复杂性,最好的方式是避免这种跨服务的事务 | ||
|
||
### 报表问题 | ||
|
||
如果分离了数据库,那么如何解决需要所有数据的后台报表应用? | ||
|
||
- 服务调用 | ||
- SQL接口 | ||
- 提供一个批量API | ||
- 指导系统将数据写入到一个共享位置来解决传输问题 | ||
- 数据导出 | ||
- 由服务主动推送数据到报表服务器 | ||
- 事件数据导出 | ||
- 当服务发生事件时,服务主动推送这些事件到一个中间件上 | ||
|
||
|
||
|
||
|
||
|