I have a nestjs app as follows:
- Gateway - HTTP
- Microservice1 - TCP (ms1)
- Microservice2 - TCP (ms2)
Gateway calling ms1 and ms2. ms1 and ms2 are the same duplicated microservice.
I would like to load the balance between ms1 and ms2. How do accomplish that in nestjs?
Thanks
Many cloud platforms have a built-in load balancer and I recommend using them. There is a fundamental problem with this TCP story from my point of view. I think that a load balancer could not distribute the TCP packets correctly because it would not know which packets belong together as a logical unit.
Since the NestJS documentation says: "... a microservice is fundamentally an application that uses a different transport layer than HTTP", you could simply create a new Nest application that runs separately but is still accessible via HTTP, because the difference is only in the transport protocol and the cloud built-in load balancer can handle HTTP in any case.
That mean:
Communication goes via the HttpModule: