知识卡片
事务不会自动防负库存
原书在事务中直接将库存减二,没有要求当前库存足够,也未展示约束。即使数据库正确串行执行两个扣减,数量仍可能变负。ACID的数据库一致性不自动发明业务校验;业务不变量必须被约束与条件更新实际表达。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Data Storage Strategies · 查看原书依据
This transaction must maintain ACID properties, as follows: Atomicity: All operations complete successfully, or none of them do Consistency: Inventory levels cannot go negative; payments must match order totals Isolation: Other customers cannot reserve the same inventory Durability: Once confirmed, the order will not be lost even if systems crash PostgreSQL, our chosen RDBMS for order processing, excels at maintaining these properties.
参考来源
- 位置:《Building Distributed Systems Designing scalable architectures with microservices, event-driven patterns, and robust deployment…》第09章《Data Storage Strategies》(来源项目book-sources;源文件:extracted/Building Distributed Systems Designing scalable architectures with microservices, event-driven patterns, and robust deployment…/_epub-src/OPS/ch09.xhtml)
- 结论依据:原文给出本卡对应定义或示例;原书在事务中直接将库存减二,没有要求当前库存足够,也未展示约束。 对原文省略和过度承诺的限定是本卡显式纠正,不能反过来当作原书已证明。
- 原始内容:This transaction must maintain ACID properties, as follows: Atomicity: All operations complete successfully, or none of them do Consistency: Inventory levels cannot go negative; payments must match order totals Isolation: Other customers cannot reserve the same inventory Durability: Once confirmed, the order will not be lost even if systems crash PostgreSQL, our chosen RDBMS for order processing, excels at maintaining these properties.