samedi 28 août 2021

Design pattern to execute multiple sequential functions as a unit of work and support rollbacks

I have a complicated review application submission process that does several steps.

ReviewService.CreateReview()

  • CheckReservedTimeslotIsAvailable
  • ProcessPayment
  • CreateMeeting
  • InsertReview
  • UpdateFinancialJournal
  • FinalizeDocuments
  • Notify

All these steps are coded inside the CreateReview() method and is becoming un-readable, hard to manage. Also the current implementation doesn't have the support of rollbacks.

So the idea is to create an Orchestrator class and build the sequence of steps. The orchestrator ensures a successful review is created if all steps are completed. If any of the step fails to complete then all of the completed preceding functions are rolled back to ensure data integrity. This is pretty much the same as Saga pattern (Orchestrated) but with slight change the steps are not micro services.

Is this the right pattern to use? Or Command pattern would be a good option? Please advise.

Aucun commentaire:

Enregistrer un commentaire