1

I am looking for an elegant way to manage workflows and rollback when needed but the system is depending on various external services most steps of these workflows are triggering by external sources (like webhooks).

An example scenario for a subscription system:

  1. User sends a subscription request
  2. The subscription created on the database with status=pending
  3. Subscription request sent to Stripe
  4. (Stripe does some black magic -like credit card verification-)
  5. Stripe informs the results of subscription (succeeded or failed) to our app via an HTTP request (God knows when, maybe in 10 seconds, maybe in 10 hours)
  6. Update the subscription on the database status=active or status=failed
  7. doSomeOtherImportantStuffWithSubscription()

Now, in this flow, if any of these steps fails for some reason (an exception thrown, database connection error, Stripe card verification error etc.) I want to rollback all the previous steps. But handling all this flow with a bunch of if-else statements is probably the worst idea, and I wonder if there is an elegant and standardized way to achieve this rollback mechanism.

I'm looking for a framework-agnostic solution but if it's important this is our tech stack:

  • MoleculerJS (with TypeScript)
  • Stripe API
  • MySQL 5.7.26

UPDATE

An example of what I'm trying to achieve:

  1. User sends a subscription request
  2. The subscription created on the database with status=pending
  3. Subscription request sent to Stripe
  4. (Stripe does some black magic -like credit card verification-)
  5. Stripe informs the results of subscription (succeeded or failed) to our app via an HTTP request (God knows when, maybe in 10 seconds, maybe in 10 hours)
  6. Update the subscription on the database failed because of a connection error
  7. Cancel Subscription on Stripe (reverse of 5th step)
  8. Delete subscription request from the database (reverse of 2nd step)
1
  • Maybe downvoter explains what is wrong with the question so I can improve it. Commented Mar 3, 2021 at 20:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.