Search code examples
javaspringweb-servicesmicroservicesapi-gateway

Communication between ecommerce webservice and payment gateway


I have query related to microservice.Suppose i have an ecommerce aplication in which i selected few products and wants to purchase them Once I select the Payment service and initiated payment then directed to Third party payment application now when payment is done it is going to redirect me at ecommerce website but now due to some reason this website is down then how does this type of transactions handled across services?


Solution

  • To handle these type of scenarios you have to use event driven approach. in simple words One service raise event to the other service by storing in message queue. the other service will pick that message. the service raising event store the event locally before publishing it. so if it breaks before publish you can always publish event from local store when service gets back . same happen with subscriber service. it will pick the event from message queue and if it's not there message remains in the queue until processed. in short the message or event is always there and whenever system gets back it can consume it.