2

I have a full-stack node.js project and I don't know what the best practice is for deploying it.

some information first: the app consists of:

  • a next.js frontend
  • a redis cache
  • a postgres sql
  • and a node.js backend

the deployment shouldn't cost too much because it's a hobby project.

Currently (as dev env) I use vercel for the frontend and my own vm for the backend

However, I would like to deploy everything in e.g. an app engine (i.e. without much config and with automatic scaling)

I just don't know what the best provider is, because there are many services, e.g. gcp cloud run, gcp app engine standart, app engine flex, firebase hosting, gcp cloud computing, all aws services, and many more...

I would prefer docker-compose, for example, on the google cloud platform with all the advantages of app-engine/cloud run, i.e. little config, automatic scaling and not too expensive, since it's just a hobby project. I hope something like this is possible. (I don't mean that I don't want to pay anything, but e.g. $20-50 a month is a bit expensive for it)

Blizii
  • 173
  • 11

1 Answers1

3

I've been there, GCP and AWS and other cloud providers can be overwhelming at first. There are so many services and sometimes it's hard to understand the differences.

Let's try to simplify first : do you need a separate NodeJS backend ? If it's a hobby project, maybe NextJS API routes are enough. This would simplify your stack greatly, because you could deploy everything in a single service on Cloud Run (front + back). API routes aren't as powerful as NestJS for example but can get you very far.

Then there's the Cloud Run vs App Engine debate. Even though App Engine is still actively maintained by Google, many people believe Cloud Run is the future. App Engine is for deploying code, Cloud Run for deploying containers, and containers are eating the world. App Engine was one of GCP's first offering and has many hidden features that can bite you. Choose what you prefer though.

Then, for persistence, again, so much choice. Maybe this decision tree can help : decision tree : Personal opinion : KISS, go with good old SQL : Google Cloud SQL with Postgres. You can very simply connect a Cloud Run service to a Cloud SQL instance.

Finally, there are many tutorials online explaining how to deploy NextJS on Cloud Run. You should find what you want.

Good luck !

Ant1k
  • 130
  • 5
  • Thank you very much for your Answer! And my Node.JS Backend, is a headless CMS called "Directus" and that is why I need a extra backend – Blizii Jan 20 '22 at 12:34
  • You might still be able to integrate API Routes with a [custom server](https://nextjs.org/docs/advanced-features/custom-server) or by catching all API routes and redirecting them to your CMS. Otherwise you can just create 2 separates Cloud Run services : one for the front, one for the back. You can then get your CMS data from your NextJS frontend service with an API call to your backend service in `getStaticProps` or `getServerSideProps` depending on your use case. – Ant1k Jan 20 '22 at 14:49
  • Okay does that mean I need two cloud run services, a google cloud sql service and a google cloud storage for the data? (pictures etc.) – Blizii Jan 20 '22 at 17:58
  • That sounds good to me yes. – Ant1k Jan 21 '22 at 13:45