知识卡片

问题卡 · 2433.j.2

为每项依赖准备退路

理解等级:中级

外部依赖不可达时,聚合服务需要提前定义继续服务或明确失败的办法。

外部依赖失败时,分别评估读与写的退路:短暂停顿后重试、切换预配置备用、从注册表动态寻找替代、请求入队延后执行,最终明确失败。前几种通常可藏在接口内部,入队则改变消费者可见的完成语义。

重试参数至少包括失败类型、请求语义、等待间隔与次数;备用服务还要求身份、状态及结果语义可兼容。恢复逻辑应在本地实现,避免再依赖一个网络“恢复服务”。记录请求及实际处理目标,有助于追踪切换后的结果。

关联:[[注册服务完整生命周期]]。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 超媒体服务 · 查看原书依据

      Basically, you want to implement your API to assume failure on the part of other elements of the system you are dependent upon and incorporate at least one of the preceding mitigating solutions for each possible failure point. Ultimately, you cannot prevent the failures, but you may be able to mitigate its effects. To quote John Gall: “Any large system is going to be operating most of the time in failure mode.”

    参考来源

    - 位置:《RESTful Web API Patterns and Practices Cookbook》第5章《Hypermedia Services》(来源项目book-sources:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch05.xhtml,配方5.16) - 结论依据:原文逐项列出重试、静态备用、动态备用、排队和放弃,并警示不要把恢复逻辑再次外部服务化。 - 原始内容:Basically, you want to implement your API to assume failure on the part of other elements of the system you are dependent upon and incorporate at least one of the preceding mitigating solutions for each possible failure point. Ultimately, you cannot prevent the failures, but you may be able to mitigate its effects. To quote John Gall: “Any large system is going to be operating most of the time in failure mode.”