Advanced architecture design
So far we have covered everything needed to setup and start writing and using microservices in Nest.js. Along the way we describe some of the drawbacks Nest.js’ implementation of microservices has. Most notably, since the microservices does not run in a separate thread or process, you may not be gaining much in the way of performance when using Nest.js microservices.
However, that is not to say you can’t get these benefits. Nest.js just doesn’t provide the tools out of the box. In most material found on the subject of running a NodeJS application in production, the one thing that is typically always covered and recommended is the use of the NodeJS cluster
module. We can do the same thing with our Nest.js application.
async
function
bootstrapApp() {
const
app
=
await
NestFactory
.
create
(
AppModule
);
await
app
.
listen
(
process
.
env
.
PORT
||
3000
);
}
async
function
bootstrapRpc() {
const
rpcApp
=
await
NestFactory
.
createMicroservice...