0

I am working on one migration engine to migrate data from older system to newer system. it is divided into 3 steps.

  1. first getting the data from older tables.
  2. prepare the request body to insert into new tables via APIs
  3. post processing steps.

Which design pattern to use here?

I was thinking of using builder pattern

In the second step where i am doing multiple API calls for inserting data into new tables. this has some order. If API call fail in between then need to redo all previous API calls. kind of rollbacking mechanism. How can i achieve that?

  • Builder pattern is a Creational pattern and has a different use case (decouple object creation form its representation). Depending on your problem you might want to have a look at patterns like [Data Mapper](https://martinfowler.com/eaaCatalog/dataMapper.html) and [Transaction Script](https://martinfowler.com/eaaCatalog/transactionScript.html#:~:text=A%20Transaction%20Script%20organizes%20all,can%20be%20broken%20into%20subprocedures.). Otherwise describe what are trying to design around - is it a DB connection and transformation stuff, is it sequential execution of steps? – orustammanapov Mar 23 '22 at 18:39

2 Answers2

0

I think you might want to go for a Pipe-Filter Pattern here as an overall design. What you describe is pretty much described here.

PsiMatrix
  • 61
  • 8
0

Here you already have pre-defined and definite steps to perform. In this case template design pattern works well.

Sequence of calling steps are fixed and Responsibility of each steps can be seggregated into separate classes and finally can be linked on template management class.

Refer this link - https://refactoring.guru/design-patterns/template-method

Sanjay Soni
  • 201
  • 1
  • 13
  • In the second step where i am doing multiple API calls for inserting data into new tables. this has some order. If API call fail in between then need to redo all previous API calls. kind of rollbacking mechanism. How can i achieve that? – Vanshika Sharma Mar 23 '22 at 12:16
  • 1
    How you can manage redo kind of rollback through api calls? do you store historical data with you to redo changes? – Sanjay Soni Mar 23 '22 at 13:45
  • No I am not storing any historical data. Here is the case that there some n number of API calls if one fails i need to revert the changes of all API calls. – Vanshika Sharma Mar 23 '22 at 13:49
  • 1
    so reverting of api calls again need to make same number of calls with existing data, am i understanding correct? – Sanjay Soni Mar 23 '22 at 16:03