0

In my new microservices arch we are planning to 2PC protocol to handle distributed TX mgmt as we are using Oracle shared DB. I am unable to find any right implementation over the web. Is there any link having proper implementation for the same?

A proper documentation on how to implement 2Pc protocol using java spring boot

CodingBee
  • 21
  • 3
  • You don't need 2-phase commit when you only have one database. – Matt Timmermans Aug 08 '23 at 12:27
  • how can i handle distributed transactions ? if any of my microservice fails i need to roll back my other microservices DB commits as well. – CodingBee Aug 08 '23 at 12:46
  • Your system should not have that requirement. https://stackoverflow.com/questions/52031350/how-acid-works-in-a-restful-micro-service-architecture/52031373#52031373 – Matt Timmermans Aug 08 '23 at 12:51
  • i may be missing something here to understand your answer. Let me elaborate my expectation. I have microservice1(m1) calls M2 for updating few records and M2 calls M3 to update/insert few records. If in case M3 failed to update then my system should roll back M2 and M1 DB transactions as well. I hope i am clear with my questions here. – CodingBee Aug 08 '23 at 13:03
  • Yes, I understand. You think you should be able to do whatever you want in a distributed architecture, and there should be a way to make it fine... but you can't and there isn't. After M1 and M2 do their updates, everything might die. The DB needs to be left in a consistent and valid state if that happens. – Matt Timmermans Aug 08 '23 at 13:19
  • So you wouldn't suggest to go for any patterns like saga or 2pc for distribution transactions. Instead of that it is better to leave the committed transactions as it is to keep DB consistency? – CodingBee Aug 29 '23 at 09:01
  • 2pc is for extending transactions over multiple DBs. That's dangerous and you should try to avoid it. Saga pattern is fine, but it needs to work like I say -- each component transaction needs to transition the global state from one consistent state to another, and the system needs to survive orchestration or choreography failure in a consistent state. – Matt Timmermans Aug 29 '23 at 11:39

0 Answers0