I’m trying to think what’s the best approach when I need data present in different services in a microservices-based architecture. In an e-commerce context, when a user creates an order the OrderService needs to confirm if the sent list of products actually exists and infer if the total price is indeed correct (data validation).
Considering I’m using CQRS, I’ve read that the command side should not query read sides since the read sides are for clients only.
Some people say I should create an event to make ProductService check for the products and publish an event to confirm they do exist and the total price is correct, which the OrderService will listen to and proceed from there.
I’ve also read that the command side should keep a copy of any needed data for operation purposes. If so, should I keep products data replica inside my command side of OrderService? Making the orders service handle every product change events isn’t too out of its scope? It just feels like too much of an overhead, but people say it’s normal in microservices. And what if I’m using event sourcing? Will I have my event store and some SQL product tables to maintain inside the command side?
Plus, after that, I still have to post an event of OrderCreated so the StockService can listen and publish an event of StockAvailable/OutOfStock. In this specific context, the flow of creating an order to be able to pay the order goes through several publications of async events. Wouldn’t it cause a possible bad user experience? I’ve personally never waited on an e-commerce website in order to be able to pay for the products.
I know, CAP theorem, but still! What’s the best approach to have a decent order confirmed-payment flow?