知识卡片

结构图卡 · 2277.o.3.d

转账响应丢失的歧义

理解等级:中级

客户端POST请求从A转500元到B后收不到任何响应,存在两种无法仅靠超时区分的事实:服务没有完成转账,或已经成功但成功响应在网络中丢失。

若把超时直接当失败并重复非幂等POST,第二次请求可能再次完成转账,造成双重转账。问题根因是业务执行结果与客户端观测分离,以及请求缺少可重复识别同一动作的语义。[[用幂等创建消除重复写入]]讨论对应方案。

结构图:

sequenceDiagram
 participant C as 客户端
 participant S as 转账服务
 C->>S: POST 从A转500元到B
 S->>S: 转账已经完成
 S--xC: 成功响应在网络中丢失
 Note over C: 客户端不能确定结果
 C->>S: 再次发送同一非幂等POST
 S->>S: 可能再次转账
这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

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

      Now what is the client to do? Did the request ever make it to the server? Was there a server-side error that rejected the request? What if the request made it to the server and was completed, but the 200 OK response got dropped on the network? In that last case, repeating the request might result in executing the transfer twice.

    参考来源

    - 位置:《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.15) - 结论依据:原文明确500美元转账POST无响应时可能已完成,再次执行可能双重转账;本卡仅解释问题。 - 原始内容:Now what is the client to do? Did the request ever make it to the server? Was there a server-side error that rejected the request? What if the request made it to the server and was completed, but the 200 OK response got dropped on the network? In that last case, repeating the request might result in executing the transfer twice.