lundi 27 mars 2023

How to perform extensive business logic and retry from where it failed

I am trying to solve a problem where a lot of transactions happening in the business logic.

For example:

The request comes to the server (Service A)

  1. Step 1 - Transaction in DB
  2. Step 2 - Call Service B
  3. Step 3 - Another transaction to DB
  4. Step 4 - Call Service C
  5. Step 5 - 3rd Party service call
  6. Step 6 - Another transaction to DB

and so on... all the steps are dependent on the previous step.

Now, the problem is, if a step failed, I don't want to roll back the whole transaction but want to start from where it failed.

Is there a design pattern/solution that exists or what is the best way to solve this problem?

One of the solutions in my mind is

Break down the whole business logic into smaller logic (Per step) once a Step is complete, it will push the message in Queue (another Topic - Step2) and so on. If any of the steps failed, that will be picked from the queue again. This will solve the problem of retrying from the step it failed but I am worried about resources. Per call, I have to push around 7-8 messages (Steps) in the queue and process them separately.

Aucun commentaire:

Enregistrer un commentaire