知识卡片
原子预留收束库存读写
针对[[库存先读后写存在竞态]],把检查是否可用、减少库存和返回结果合成一个服务操作,并由本地事务保证该操作的并发正确性。调用者拿到预留结果后再继续其他步骤,使跨服务流程不再携带“先读取稍后写”的易变假设。预留仍需释放或补偿,不能凭一个方法名就认为外部支付和配送也一起原子提交。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 保持状态一致 · 查看原书依据
Put operations that read and write data into the same service call when possible. For example, if we rewrite the code so that we can check for inventory availability, reduce it in the database and return the value as one operation. This practice removes the read-dependent write due to inventory.
参考来源
- 位置:《Software Architecture and Decision-Making》第07章《保持状态一致》(来源项目:book-sources;源文件:extracted/Software Architecture and Decision-Making Leveraging Leadership, Technology, and Product Management to Build Great Products… (Srinath Perera)/_epub-src/ch07.xhtml)
- 结论依据:所引连续原文给出本卡机制或取舍;条件与示例结合本节已读上下文解释。
- 原始内容:Put operations that read and write data into the same service call when possible. For example, if we rewrite the code so that we can check for inventory availability, reduce it in the database and return the value as one operation. This practice removes the read-dependent write due to inventory.