suppose there are four classes
class Product {
private Long productId;
}
class ProductImage {
private Long productId;
private Long productImageId;
}
class ProductAttachment {
private Long productId;
private Long productAttachmentId;
}
class ProductDto extends Product {
private List<ProductImage> images;
private List<ProductAttachment> productAttachments;
}
in the micro-service architecture, the service interface is designed as follows:
1 Fine granularity: provide three separate interfaces, which are called by other services to obtain data, and return directly to the front end
interface ProductService {
Product getProduct(Long productId);
List<ProductImage> listProductImage(Long productId);
List<ProductAttachment> listProductAttachment(Long productId);
}
2 coarse granularity: provides an aggregation interface, which is called by other services, and the Api gateway only forwards and returns to the front end
interface ProductService {
ProductDto getProduct(Long productId);
}
which way do you prefer, and how to grasp the interface granularity of the service layer?