• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

158
Views
best practice to do rollback within multi-phase update?

we have a data object whose attributes are distributed among 3 parties,

  1. an internal service using http
  2. cloud
  3. DB

When it comes to updating the data of that object, we don't want to leave the object partially updated. So if all parties are involved for updating, will do

1 -> 2 -> 3 

sequentially. But if the update is successful at step 1 and fails at step 2, then we need to rollback step 1; if step 1 & 2 are successful, and step 3 fails, then step 1 & 2 both should be reverted. This is a spring boot 1.4, Java 8 application. Is there any elegant way for me to achieve it programmatically, rather than try/catch in step 2 & 3?

Hope I explain it well. Any helps/clues are deeply appreciated

about 3 years ago · Santiago Trujillo
2 answers
Answer question

0

There are integration patterns you could take a look at, and libraries that implement these patterns for you such as Apache Camel, or propriety products such as Mule (I think that is expensive you would probably never choose that), or a business process management flow, but these are all design decisions you will need to make yourself. It may be perfectly ok to decide not to use any of these more heavy weight approaches. There is allot out there on integration you can check out that field as much as you need to find a suitable solution, but I wouldn't invest too much time in it, just figure out what will be good enough.

Note: you might find material on distributed transactions, and you'll find people who believe in them, just like how some people believe in the Easter bunny as a child. I'm not going to tell you they aren't real, (having done so in the past I have received down votes ): ), but I will just say I have yet to witness them, and don't expect to.

about 3 years ago · Santiago Trujillo Report

0

If I understood well, the 1st and 2nd call goes outside of your scope and you can't just roll back easily as you can in a DB transaction? You can apply a compensation pattern in order to compensate what was already updated.

  • You need to store your object state before the update process.
  • If something goes wrong in step 2 or 3, a compensation handler will be triggered in order to revert the changes (it will make an update with the previous state).
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error