Home > Back-end >  Building a Node app should I use App Engine or Google Cloud Run?
Building a Node app should I use App Engine or Google Cloud Run?

Time:06-13

I am creating a Node app it has express, swagger and Agenda for running scheduled Jobs. What is the best way to deploy it in GCP. Should I use App Engine or Cloud run.

From what I understand in Cloud Run it will run in a container like docker for App Engine it will just use my application and host it. Please enlighten me what should I do?

Cheers, Cam

CodePudding user response:

App Engine is a Platform-as-a-Service. It means that you simply deploy your code, and the platform does everything else for you. For example, if your app becomes very successful, App Engine will automatically create more instances to handle the increased volume.

It auto scales from 0 to unlimited instances (It uses GCE underneath). It comes with 2 flavors Standard Environment and Flexible Environment. Standard Environment is really fast, scales down to 0 instances when no-one is using your app, scales up and down in seconds and has dedicated Google services and libraries for caching, authentication etc. The caveat with Standard environment is that it is very restrictive since it runs in a sandbox. The recent additions are Node.js (8.x) and Python 3.x. Flexible Environment is more open as it allows you to use custom runtimes as it uses docker containers. Thus if your runtime is not available in the provided runtimes, you can always create your own dockerfile for the execution environment. The caveat with it is, it requires having at least 1 instance running, even if no-one is using your app, plus the scaling up and down requires a few minutes.

Read more about App Engine

App Engine is for deploying code, Cloud Run for deploying containers, and containers are today’s requirements.Cloud Run runs containers, so for each release you have to build a container and push it to GCP.

Cloud Run, App Engine Flexible and Newer runtimes of App Engine Standard are designed for portability (you can use open-source libraries or standard libraries and not just Google Libraries). Cloud Run and App Engine Flexible allow for custom runtimes.

Cloud Run gives you the freedom to expand your infrastructure into hybrid and multi-cloud environments.

Read more about Cloud Run

Differences you should consider:

  • For a low-traffic application, Cloud Run or App Engine Standard which is set to automatic scaling are both cheaper than App Engine Standard which is set to manual/basic scaling or App Engine Flexible. Cloud Run only runs when it is serving requests. App Engine which is set to automatic scaling shuts down when it is not serving requests. This means for both types, you're not using resources when your application is not running and Google only bills you for resources that you consume. In addition, App Engine Standard provides a free daily quota of resources so you're only billed for consuming resources above the free quota. App Engine Flexible or App Engine Standard set to manual/basic scaling must have at least 1 instance running continuously, which means they run for a full month which in turn means you're going to pay more.

  • App Engine responds on average 56 ms faster than Cloud Run. The huge caveat here is that these times vary widely between runs, sometimes tripling or quadrupling The total request size from Cloud Run was larger because it doesn’t gzip files by default. The big difference between the two services is that Cloud Run doesn’t run your container unless it’s getting requests. When a request comes in, it does things: [i] boots up the container [ii] serves the request [iii] shuts down the container Of course, you also save a lot of money doing it this way, so the tradeoff here is whether you care more about optimizing your speed or your cost.

  • AppEngine can only be deployed to a single region. If you want an AppEngine app to be multi-regional then you need one project per region. Cloud run allows you to deploy a service to every region within a single project making your API truly global, all within a single project

  • Cloud Run also allows you to set up a static IP address, something you cannot get with AppEngine. This is helpful for situations where you need to relay mail or connect to some other service that restricts access by IP address. Also AppEngine still has some things Cloud Run doesn't (like Identity Aware Proxy) have.

  • The docker image support in Cloud Run is also more versatile than what you get from AppEngine Standard, and Cloud Run has more robust options to choose from (more ram, cpu, etc).



1https://cloud.google.com/appengine/docs/standard/nodejs/quickstart 2https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-nodejs-service

  • Related