聊聊微服務架構中的事務處理

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"當從一個單體系統轉向微服務架構(microservice architecture, MSA)時,處理分佈式系統帶來的複雜性是一個挑戰。事務處理是其中的首要核心問題。在一個 Web 應用程序中使用本地事務完成的典型數據庫事務,現在是一個複雜的分佈式事務問題。在本文中,我們將討論造成這種情況的原因、可能的解決方案以及使用 MSA 開發安全事務性軟件系統的最佳實踐。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"數據庫事務:入門"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在我們舊的單體應用中,我們用數據庫事務來實現全部或全無的數據操作,同時保證數據一致性。我們主要使用 ACID 事務,這些可以在關係型數據庫系統中見到。下面是快速回顧:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"原子性(Atomicity): 所有的操作都成功執行或者所有都一起失敗。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"一致性(Consistency): 數據庫中的數據保持有效狀態,遵循其規則,例如引用完整性。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"隔離性(Isolation): 分離的事務並行運行,不會相互干擾。這應該是因爲事務在其隔離的環境中運行,其它事務不能看到期間發生的變化。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"持久性(Durability): 事務提交之後,更改會被持久地保存,例如持久化在硬盤上,因此數據庫服務器的臨時崩潰不會丟失數據。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"我們可以想象使用如下所示的 ACID 事務,將資金從一個人的賬戶轉移到另一個人的賬戶。"}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章