cerinoligutom / GraphQL-Starter

A boilerplate for TypeScript + Node Express + Apollo GraphQL APIs.
MIT License
103 stars 22 forks source link

Process managers & Load balancing #32

Closed alaamh closed 2 years ago

alaamh commented 2 years ago

Hi @cerino-ligutom amazing design and nice architect, let me ask you about your suggested approach for Cluster/Load balancing? I usually use PN2 Ecosystem where there is no point in actually using it here.

cerinoligutom commented 2 years ago

Thanks! Really up to you tbh. Depends on what are your infra options though I recommend using the tooling around Docker. Really convenient and reliable.

If you're using Docker, just use any tooling around it like K8S (Kubernetes) or any PaaS that supports Docker images/containers then scale the containers based on your needs. If you're self-hosting, I recommend Dokku. And yes, PM2 gets redundant as Docker is the one managing the process. You can leave the load balancing with Dokku, see here. If you're hosting on AWS/GCP/Azure without using K8S, then use their managed services. For example in AWS, you could spawn an Elastic Beanstalk instance using a Docker platform and uses the Docker image you've built with this boilerplate then use their Elastic Load Balancer for load balancing. If you go K8S, then yea everything's on K8S. Lots of options, left it unopinionated intentionally so you have the freedom on infra 🙂

If you're not using Docker, it's just the same as any Node app. Build the app, npm run build:prod, to get the build artifacts. You'll see a build folder with the compiled TS then treat it like any other node app. Pick your preferred flavor for your process manager and load balancers. If you prefer PM2, then you could make an ecosystem config around the build artifact and run ./build/src/app.js.

alaamh commented 2 years ago

Excellent, Dokku looks promise Thanks again.