'Should a microservice call itself or call an internal function

I'm working on a old project for my company and I have found a strange code practice.

We have multiple APIs:

Account/CustomerInformations => Should return all information
Account/CustomerName => Return just name
Account/CustomerPhone => return just phone 

In the code of function CustomerInformations() they are calling the other APIs of the same service (micro-service is calling itself) (Account/CustomerName, Account/CustomerPhone) which I found really strange, because I think that it's not a good practice.

After asking the Architect, the reason he gave is that it's the only reason to pass through the load balancer and make the call quicker.

enter image description here

I think that we should call a Task to do the work instead of calling the micro-service it-self.

What are the best practice in this kind of situation?



Solution 1:[1]

This seems like a no-brainer. That pull-all function needs to be refactored to pull all the data from the DB in one-go, using paging if needed, rather than offloading it to other endpoints in the same function. Every single time this service calls itself it is wasting time traveling through your network path, adding latency, and adding cost. Your architect is an idiot if he thinks "going through the load balancer" is going to make it quicker -- it's going to make it easier to be LAZY and not implement this correct

Solution 2:[2]

how's table structure look like? if all Informations are reside in same table, then it may be good to use internal API. There may be some missing Information, you may want to check if there is some way to introduce LocalOptimization or already there in code, that use smartly to identify whether to call Internal API or call external API. just assuming but small code refactoring should help here.

Solution 3:[3]

As I understand, the current reasoning to not keep things internal, is to mitigate potential performance issues. If there were indeed performance issues in the past, than keeping things internal might not be the way to go and could in fact cause degradation of service performance.

You could opt to split out the CustomerInformation into its own microservice, which would in effect split the calls to CustomerName and CustomerPhone in much the same way, but without the need to call "itself".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vizzyy
Solution 2 kus
Solution 3 marc_s