I need to fetch and filter data from three different services: ProductService, PriceService, and StockService. My goal is to get products that belong to Category = 54, have stock available, and are sorted by price in ascending order.
Had it been a monolithic architecture, I could have done it like this, for example:
But since the system is distributed, I don’t know how to do it.
SELECT * FROM Products JOIN BLA BLA
WHERE ...
ORDER PRICE STOCK
I could do something like this:
const products = ProductService.getProducts();
const prices = PriceService.getPrice({ ids: [54, 436, 34, 653, 43, 6524, ...] });
const stocks = StockService.getStock({ ids: [54, 436, 34, 653, 43, 6524, ...] });
// Filter and sort
const result = mergeData(products, prices, stocks)
.filter(product = etc ...)
bla bla ...
.slice(0, 16);
However, this approach is not feasible due to the large volume of data (millions of rows). What would be an efficient way to handle this scenario?
If it requires this much effort just to perform sorting, is a distributed system the wrong choice for this task? We switched to a distributed system to scale because the Price and Stock services handle transactions every second.