Hey, my question is kind of hard to explain so I apologize in advance.
I’m trying to implement microservices for our ecommerce and I’m having issues on how to respond to a request when the actual logic and data needs to be determined by other ( 2-3 ) services.
In order to make it easier to understand, I’ll give an example.
Lets say User A is trying to buy a product. after clicking on “check out” button these steps should happen.
Request comes in:
- Ecommerce service:
- Check if product has enough quantity in inventory.
- Publish an event indicating a new order has been created.
- Anti Fraud service:
order:createdand checks whether the user is a fraud or not
- Publishes an event indicating the check was successful.
- Payment Service:
check:succeedand creates a url to the gateway.
- Sends the gateway url to the user, possibly publishing
payment:createdevent. (( this is where my question is ))
Since all of these steps are asynchronous, how do I respond to the
After the user has requested to checkout, the ecommerce service creates an order and responds immediately with the orderId of newly created order, on client-side the user has to request periodically and check whether the status of order is
PENDING PAYMENT, in order to achieve this, the payment service needs to publish
payment:created after the order has been approved by the system and then ecommerce service can update the order.
My solution works, but I’m really new to microservices and I want to know if there’s a better way to implement this.
I really appreciate if you read this far, Thank you for your time.