Intro
Hey, my question is kind of hard to explain so I apologize in advance.
Question
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.
Flow
Request comes in:
- Ecommerce service:
- Check if product has enough quantity in inventory.
- Publish an event indicating a new order has been created.
order:created
- Anti Fraud service:
- Receives
order:createdand checks whether the user is a fraud or not - Publishes an event indicating the check was successful.
check:succeed
- Receives
- Payment Service:
- Receives
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 ))
- Receives
Since all of these steps are asynchronous, how do I respond to the Request?
Possible Solution
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.
Building Microservices: Designing Fine-Grained Systemsbook is on the way. I will definitely readEnterprise Integration Patternsas well.