Hi, Folks i am building a sync API that needs to write to multiple external services transactionally. I am trying to figure if/best way to use temporal for this.
My API needs synchronously to do the following:
- Write to Database
- Write to service A
- Respond back to the client
One way we are thinking of solving this problem is by building a cleanup temporal workflow. i.e the workflow only has a single step, which is to wait for 5 mins and if no signal received do clean up of steps 1 & 2.
So the steps in the API would be:
- Start a cleanup workflow that goes into wait state (below steps not part of the workflow)
- write to database
- write to service A
- Signal the clean up workflow to close out since all write actions are complete
- respond back to the client
If the clean up workflow does not receive signal (step 4) within 5 mins it goes ahead and reverts any possible changes in database and service A
Would love to get your thoughts on if there is a better way to do this distributed transaction using temporal.
One of the alternative ways we looked at is using the SAGA on with a synch workflow start and local activities. But i am not completely sure how the states are saved in for local activities (i.e what happens if host crashes)