Transaction Management Patterns In Brief

本文探讨了在使用Spring框架进行事务管理时的多种模式,包括翼与祈祷模式、共享事务资源模式、非事务访问模式、尽力而为的一阶段提交模式及XA两阶段提交分布式事务模式,并强调选择适合场景的模式的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        There are several patterns you can take when you have faced with balances on transaction management, especially when you are using spring framework to do such things. The idea is not mine, I just give a brief note here, although I have used some patterns myself, but I didn't name them.


        I start from the simplest pattern.


 

  • Wing-And-A-Prayer Pattern
          this is a type of anti-pattern or worse practice, it means, you manage transaction on A resource, but data access on B resource, in chinese "驴唇不对马嘴", :-)

  • Shared Transaction Resources Pattern
          the data access request are sent to resource A, the transaction are managed against resource A too, that's, the normal situation, right?

  • Non-Transactional Access Pattern
          we have 2 or more resources,  in this pattern, we only guarantee ONE long transaction against one of the resources,  as to data access requests against other resources, we let them go ( auto commit, as u see). 

  • Best Efforts 1PC Pattern
          we have 2 or more resources too, just like the scenario in Non-Transactional Access Pattern, but only guarantee ONE long transaction is not enough, and we don't want to use XA distributed transaction management either, so what we do? 
          In Best Efforts 1PC Pattern, we start all of the local transaction against each resources we manage, we commit or rollback them all as per situation, but don't guarantee the data integration when errors occurs at the point of commit or rollback, there is only 1 phase commit and we do our best to make sure the transactions to be managed properly, that's why it's called Best Efforts 1 PC Pattern. 

  • XA 2PC Distributed Transaction Pattern
          it's natural to resort to XA 2PC Distributed Transaction Pattern when the transaction involves more resources, we all know it, but we also know that XA 2PC distributed transaction brings performance penalty too.

      So, you see, no matter which pattern you choose, choose one that's suitable to your scenario!
      BTW, Taobao guys have another solution for transaction management, but their solution is specific to their scenario too, so pick the one that 's best suitable to you. 







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值