知识卡片
服务三层职责分离
订单服务把接口、业务和数据职责分开:API 层验证请求并形成响应,业务层决定下单、取消或支付等动作,数据层负责持久化。请求沿层次进入,业务逻辑不应被路由或存储细节吞没;分层的价值在于让各自变化有清楚的边界。
结构图:
flowchart LR
A[客户端请求] --> B[API层: 校验与响应]
B --> C[业务层: 执行业务能力]
C --> D[数据层: 持久化与读取]
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 2 章《A basic API implementation》(源文件:_epub-src/OEBPS/Text/02.htm)
- 结论依据:2.2 节明确列出 API、业务和数据三层职责;图 2.3 旁的文字说明请求先由接口层校验,再由业务层处理,最后数据层持久化。
- 原始内容:the data layer knows how to interface with the source of data; the business layer implements the service’s capabilities; and the interface layer implements the service’s API. ... When a user request reaches the orders service, it’s first validated by the interface layer. Then the interface layer interfaces with the business layer to process the request. After processing, the data layer persists the data contained in the request.