vendredi 24 avril 2020

Transaction issue when DB Call happens after Rest Call

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
    }
}

SCENARIO 2: Here My DB call depends on REST Response

@Transactional
class MyService {

    public void DBCallDependsOnRESTResponse(){

        //REST Call
        //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?

Aucun commentaire:

Enregistrer un commentaire