I'm very new to micro-services but am trying to learn, so apologies for any ignorance or incorrect information.
I have been looking at event-sourcing architecture for microservices and I have a question when it comes to making a command/post requests and having to wait for their response.
Take this example: I want to create an order but in order to create the order it must be checked to see if the customer has enough money to place it. So I make a post request. This might be straight to the order microservice or might be routed or handled via an api gateway.
From an event sourcing architecture this is my understanding on how it might be created.
- Order service would receive order information via a post method and add the order in a pending state.
- The order service would publish a order created event.
- The pricing service has subscribed to the event. So it will check how much that user/customer has. 3a. If the user has enough money, it will reserve the amount. It will then publish a credit reserved event. 3b. If the user doesnt have enough money it will publish credit exceeded event
- The order service will have subscribed to both of these events and will either put the order into placed or deny it. (I dont know exactly what it would do if it is denied but it will not be allowed)
(Image is just for reference, this doesnt not imply they world talk directly to each other)
Now a few questions come off of the back of this which I hope someone can please help me.
The user is going to call this to place an order. They are going to want a response when they place this to know if it was placed or not. How do you handle waiting for command operations that you need a response to, and that response relies on waiting on other microservices potentially. If my api is to wait for a change in the order, how is an event picked up via an endpoint?
How does cross microservice validation work. For instance, say before I create the order I want to know if the user it is for actually exists. is this handled by the api gateway which will do initial validation based on the user info?
I understand there is a idea of anonymous microservices (instead of authoritity where each service owns a data set). For instance, the order service would have a copy of all the users and their wallet, so it can check its copy. (same with the users to check it exists). is this the way to go.
Is any of this even correct. Any help would be much appriciated.