知识卡片
重试必须理解动作语义
网络失败不能证明业务未执行,因此自动重试前必须判断重复动作的后果。
自动重试以重复不会制造额外业务效果为前提;网络失败或某些5xx/408不等于服务一定没有执行。书中建议对GET、HEAD、PUT、DELETE等具有适当幂等语义的请求恢复,不能把普通POST/PATCH直接重放。
配置等待和次数,并尊重目标服务限制,防止高频重试加剧故障。错误码也应区分,不能对所有5xx一律恢复。即使PUT也需正确实现副作用及条件写语义;重复请求安全不代表一定还能得到相同响应。
关联:[[为每项依赖准备退路]]、[[用幂等创建消除重复写入]]。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体服务 · 查看原书依据
Don’t attempt retries on nonidemptotent HTTP methods like POST or PATCH. Instead only support these mitigations for GET, HEAD, PUT, and DELETE. In rare cases, HTTP POST operations can be interpreted as failures even when they are completed successfully; for example, when the target service’s 201 Created response never makes it back to the API consumer that made the call.
参考来源
- 位置:《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)
- 结论依据:原文限制可重试的方法,解释成功响应丢失造成假失败,并讨论错误类型、间隔和目标服务负载。
- 原始内容:Don’t attempt retries on nonidemptotent HTTP methods like POST or PATCH. Instead only support these mitigations for GET, HEAD, PUT, and DELETE. In rare cases, HTTP POST operations can be interpreted as failures even when they are completed successfully; for example, when the target service’s 201 Created response never makes it back to the API consumer that made the call.