I have service oriented architecture with couple services.
Product - store list of products
{
id: number,
price: number
}
Categories - store category information + the list of product ids
{
id: number,
parentCategory: number,
productIds: number[]
}
Lets assume that I have such category instance
{
id: 1,
parentCategory: null,
productIds: [1, 3, 4, 5, ....]
}
I need to get 10 products from the category above sorted by product price.
Category service processes that request and because it doesn't know anything about the price it has to make the request to Product service like that:
/api/products?
ids=<list of all product ids>
limit=10
sortBy=price
which won't work well when the category has a lot of products.
What is the recipe in such case? Thanks.
I agree with victor — POST request could solve potential issue. If you are concerned about performance, for example, in case of thousands of ids, you should consider merging these services together. Or duplicate prices data in Categories service.
Data duplication and merging several services into one for performance reasons are normal situations in microservices architecture. But if your Products service only stores information and doesn't have any business logic, then I definitely would consider merging.
Also, consider having all ids already sorted in Categories service. For me it would be the best solution in this case if Products service will not do anything business useful and only sorting