I'm working on a old project for my company and I have found a strange code practice.
We have multiple APIs:
Account/CostumerInformations => Should return all information
Acount/CostumerName => Return just name
Acount/CostumerPhone => return just phone
In the code of function CostumerInformations() they are calling the other APIs of the same service (micro-service is calling itself) (Acount/CostumerName, Acount/CostumerPhone) 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.
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?
CodePudding user response:
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 infact cause degradation of service performance.
You could opt to split out the CostumerInformations into its own microservice, which would in effect split the calls to CostumerName and CostumerPhone in much the same way, but without the need to call "itself".
CodePudding user response:
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

