Search code examples
javaspringsocketsresttemplate

How can multiple services interact remotely to ensure normal flow


everyone. I have a problem. Can you help me? Thanks

Background:

Server A communicates with server B by RESTTemplate, and server B communicates with client C by socket The whole process is basically as follows: C makes A request, goes to A, and returns the result to C: C-->B-->A-->B-->C There is also the following business A-->B-->C-->B-->A

Question:

ABC is a remote call, there are always some accidents in the middle (such as C sent a request, C hung or network timeout, C could not receive the message, that is, C-->B-->A-->B-->C), how to ensure the occurrence of unexpected circumstances, but also to let the business closed loop Is there a mature plan?

My try:

I tried to save the state in B, and then let C request it again and decide which step to continue according to the situation, but I felt it was too cumbersome to do so, and I didn't know if there was any other plan


Solution

  • Your use-case is a common problem in business transactions which span multiple services and because of distributed nature there could be many failure scenarios which are out of service control like network issues, latencies, unexpected failures. There are several techniques and the most commonly used is Compensating transaction by using Eventual consistency or Saga pattern