What is the proper way to deploy SSR web app on GCP?

Viewed 1001

Starting point: I have a universal JS app (built on Next.js, Nuxt.js, Universal Angular, etc.) and I want it to be up & running on GCP (I think the same question can refer to AWS, principles are the same). The app is not a "real" back-end (with db connections, business logic, etc.), it's more kinda "frontend-backend" - all it does is only SSR of frontend. The app is containerized using Docker. The application should be production-ready (shouldn't be deployed on some beta services).

I have encountered 4 possible options:

  1. Compute engine
  2. GKE (Kubernetes)
  3. Cloud Run
  4. App engine

The question is next: what is the GCP service, that best fits this app's need?

1 Answers

I'm a big fan of Cloud Run, and I can't recommend you another best place. But why in words

  • Compute Engine: Traditional server with all the boring things to manage yourselves (High Availability, backups, patch/update/upgrade). And don't scale to 0. for HA you need 3 VM (at least, in a same zone). Quite expensive.
  • GKE: Very similar to compute engine. In addition you need skills on K8S.
  • AppEngine: great solution, but less customizable as Cloud Run. In addition, you can't serve directly container on App Engine standard, it's only possible on the flex version, custom runtime (you don't scale to 0, but to 1); the main advantage here, is the easier server management compare to Compute Engine, and a native regional HA included.

For Cloud Run, Cloud Function and App Engine (standard version with automatic/basic scaling mode), the service can scale to 0. Thus, when a request come in, the service is started and took a while before being able to serve the request (about 300 -> 500 ms, except if you use an heavy framework, like Spring Boot, it takes several seconds).

If this cold start is a problem, you can set a min instance to keep warm one instance and thus to discard this cold start.

  • You can't do this with Cloud Functions
  • App Engine, you pay, without discount, the unused instance (kept warm but not serving traffic)
  • With Cloud run, you pay 10x less the instance cost when it's idle (90% of discount).

Sadly the min-instance on Cloud Run is still in Beta (I'm sure it will be very soon in GA, but it's not today "production ready" as you say.

Note: from my experience, Beta version are production ready, you simply don't have financial compensation in case of issue

IMO, I recommend you to have a test on Cloud Run (which is in GA) without the min instance param and see if the cold start is a real issue for you. If it is, you have the beta param, but it's possible that it will be GA when you consider it!

Related