0

I am using Spring Boot and my application is just Monolithic for now, may switch to microservices later.

SCENARIO 1: Here My DB call Does NOT depend on REST Response

@Transactional
class MyService {

    public void DBCallNotDependsOnRESTResponse(){

        //DB Call
        //REST Call, This restcall gives response like 200 "successfull"
    }
}

SCENARIO 2: Here My DB call depends on REST Response

@Transactional
class MyService {

    public void DBCallDependsOnRESTResponse(){

        //REST Call, making a Real Transaction using BrainTree
        //DB Call, HERE DB CALL DEPENDS ON REST RESPONSE
    }
}

In case of Scenario 1, I have no issues as DB gets rolled back incase REST fails.

BUT, incase of Scenario 2, REST call cannot be rolled back, incase if any exception occurs at DB call.

I already searched in google for above, I found some solutions like we need to use something like Pub-Sub model system seems, BUT I could not able to get that concept to my head clearly.

I will be glad if someone could able to provide solution for SCENARIO 2. How Other Ecommerce businesses handling their transactions effectively, I guess my query related to some Architecture design.. Please advice some good architecture approach to solve above Transaction issue. Do you think using some Messaging system like Kafka will solve above issue..? FYI, currently, my application is Monolithic, shall I use Microservices? Do I need to use two-phase-commit or Sagas will solve my problem? Does Sagas can be used for Monolithic application?

EDIT: Regarding RestCall: I am actually making a Real Transaction using BrainTree, which is a Rest Call.

john
  • 925
  • 1
  • 12
  • 20
  • Looking for an answer still.. – john Apr 25 '20 at 10:13
  • There is no perfect answer for this question. As soon as you start the rest call then you should handle the data consistency by yourself on the application side that means if you need to rollback the call you made to BrainTree then you should make a call to braintree if possible to revert back the corresponding transaction. If not possible then you should create a call to compansate the transaction again by making a rest call. – cool Jul 17 '20 at 19:05

1 Answers1

0

Can you elaborate what are you achieving from rest call? Are you updating any data that will be used by the DB call?

If the 2 calls are independent, will the order be of importance? Since db call will be committed at the end of method itself

  • I just updated my query above, My RestCall is bascially making a Real Transaction using BrainTree – john Apr 25 '20 at 07:20
  • Scenario1, DB and Rest are independent, but in case of scenario2, Restcall is actually a REal Transaction using BrainTree, and this response fields should be used to update in DB, so DB call has to make after REST call – john Apr 25 '20 at 07:23