we have a data object whose attributes are distributed among 3 parties,
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
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.
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.