I have two micro services built using spring boot,
One micro service is: "payment" Which handles actions related to payments.
- Like creating a payment link.
- Getting the latest status of payment and storing that information in DB (via polling). There is an UI Screen to which user redirects once payment is done and from there polling starts.
- Notifying latest status of payment to other micro services using kafka or any other pub sub.
Other Micro service is: "order management system" which handles actions related to orders.
- Creation of payment link by calling "payment" service and sends it to user via email or some other media.
- Also stores payment link in DB for resending Email if initial email failed.
- If failed Event is Received from "payment" service then "order management system" creates a new link and sends it to user.
so far everything is good.
Now there is a new requirement to show the latest payment link on the UI(where polling happens) once there is a payment failure along with sending an EMAIL.
Here are the steps When there is a payment failure.
- "payment" service came to know that payment is failed, so puts an event to pubsub.
- UI will receive in response that payment is failed. (Here we need to show the new link)
- As "order management system" received the payment failure event , "order management system" creates new payment link by calling "payment" service and sends email again to user.
Now the problem is , How can I show the new link to the user on the UI? If let us say UI calls "order management system" for new link , it might not have the new link because it haven't received the Event.
I cannot call "order management system" Service in payment service because, I don't want to pollute payment service with order related data.
I want UI to call "order management system" service for polling but "payment" service also sends event to pub sub which other services are interested in. So "order management system" receives updates via event as well as via rest call now there is a race condition in which some times two new payment links can be generated and last updated will be stored in DB or first which I don't want.
I don't want to stop listening to events from "payment" service because some times "payment" services polls for pending payments(either success or failure) in the system and will give notifications to "order management system" for taking appropriate actions.
How can I give new payment link to UI on a payment failure Event?