Yeah! Good question. But our case was a little bit different. Our server runs more than one application using pm2.

The value of NODE_APP_INSTANCE is set by pm2 which is a read only value. And NODE_APP_INSTANCE=='0' will not always be available for our API application because here pm2 runs more than one application.

But in my solution you will find that we have more control over the instances because we can assign custom name to the instances and recall them from code.

Also from my solution you will find that I've divided the clusters into two separate groups so that I can distribute task group-wise and scale them separately.

Associate software engineer @BrainStation-23 since 2020