Where should I run my Code on Google Cloud Platform?

Google Next 19

The last month I had the opportunity of assists to Google Next, this is one of the most amazing events that Google and partners organize each year to share news about updates, innovation, new products and services on google cloud platform.

This is an event very hoped for google developers and people follower of Google tecnologies, and as always the event was amazing, I met a lot people and I learned a lot.

So today, I wanted to share one of the things I learned about where should I run my code?. In the company where I work it was a very commun question. Since Google Cloud Platform offers different services that allow you to run code in different programming languages. When I started working on GCP only were available Google Compute Engine and Google Appengine Standard.

Through time Google has been evolve and the last years have been releasen new services and products to run code as for example:

Google Appengine Flex
Kubernetes
Cloud Run (announced this #googlenext19)

So, now we have three more ways to run code in addition to the others I mentioned before. This open our minds to the concern where should I run my code?.

In my case I was wondering should I migrate my apps from Google Appengine to Kubernetes? or from Appengine to Cloud Run? This question came up only because the trend is Kubernetes.

If you have a similar concern let me guide you through what Brian Dorsey (Developer Advocate) shared with us this last #googlenext19 explaining each one of the services we mention before and what would be the ideal use for each one of them. But to give a quick answer we are going to say that it depends on your requirements and needs.

1. Google Compute Engine (GCE)

This is one of the first products offered by google since the beginings of GCP. Which delivers Virtual Machines running on Google Datacenters that give you the advantages of being distribuited around the world and the scalability of Google as well.

Basically enables scaling from single instances to global, load-balanced cloud computing, come with persistent disk storage, and deliver consistent performance.

Those virtual servers are available in many configurations including predefined sizes or the option to create Custom Machine Types optimized for your specific needs. Flexible pricing and automatic sustained use discounts make Compute Engine the leader in price/performance.

So, as summary we can say that if we want a complete control over fisical servers avoiding any concerns related to network and servers localization we can use compute engine to host our workloads overall when these are existing applications that we want to migrate to the cloud.

You can read more about here

2. Google Kubernetes Engine (GK)

This is one of the newest products that was released the last year. Where google has been marketing a lot. It was designed on containerized applications and it has great complementary services as istio for monitoring, stackdriver for logging and debugging that improve the way to build applications based on micro services architecture.

It has become on the most popular service used to run code and workloads on GCP. The opperational model is based on serveless, so you don’t have to worry about infraestructure management, it also come with fully managed security and you pay only for use.

The programming model incorporated it has the following characteristics:

Stateless: each request is treated as a separate transaction that is unrelated to any previous request
Service-based: based on micro-services
Event-driven: (it means that the communication amount services is based on events. You can use pubsub for this.)
Open: it means that if you want to move your application or code to another cloud provider you can do it easilly.

So, as a summary. If you need to have custom runtimes and a little bit more control over servers and applications settings you should use GK avoiding complications with networking and infrastructure.

read more about GK

3. Google Cloud Functions (GCF)

A very complementary solution for micro services architecture. It also incorporate the same opperational and programming models as kubernetes since is serveless architecture as well. But this is ideal for small integrations with external services that you could need.

It also can be used for data transformations, http requests and espefic tasks that can be considered as functions. Even more can be used for small backends for mobile applications.

It also autoscale and pay only for use. So, you only have to set the programming language without any concerns about runtimes or networking.

A very cool complement for cloud functions is pubsub since natively support triggers to run our code based on events through pubsub. So cloud functions can be triggered when something happend in another service.

read more about GCF

4. Google Cloud Appengine (GAE)

what is the ideal use for GAE?

Is the platform as a service (paas) provided by Google. Here you only have to worry about conding and there are two versions:

Appengine Standard
Appengine Flex

The standard version is characterized because only runs applications under the established runtimes provided by Google, although it is available for several programming languages as Go 1.11, Python 2, Php 5.5 and java 8. Which means that for the case of python you can not install third party libraries compiled in another language as C for example, so this brings the need of having an more flexible version. So the last year Google decided enable the second Generation of GAE standard where enables the third party libraries running in sandboxed proceses and this time available for Go 1.12, Php 7.2, Python 3.7 and support for two new languages which are Ruby and Node.

The flex version come up due to the need of having custom runtimes. I mean enable appengine to execute third party libraries. So, this is the main advantage of GAE flex. Despite that is much more expensive comparated to the standard version you only pay by use as well.

Which are good fits and constraints for GAE?

Good fit:

Http/s request-response
Statess serving applications
Scaling to high traffic

Constraints:

  1. Standard
Runtimes for Python, Java, PHP, Go and Node
Http/s only

2. Flexible:

Inherit Dockers constraints
No best for very low traffic site

5. Google Cloud Run (GCR)

Each time more and more companies are migrating to the cloud. They need to have more control over some resources in the servers but without the concept of the serviceless architecture and microservices with the capabilty of migrate to any cloud provider easilly. So, Google announced this googlenext19 the its new product called Cloud Run which is based on containerized applications with code listening on $ PORT for HTTP, autoscaling from zero to 1000s of instances with the payment only for current CPU and memory used.
 
Something very cool on Cloud Run is that if you need to create a cluster you can put you cloud run into kubernets

Which are good fits and constraints for GAE?

Good fit:

Stateless
HTTP request-response workloads
Scale: way up, down to zero, bursty
Specific runtime requirements: language, dependencies, etc.

Constraints:

Must use containers
Decide on build process (Cloud Build, etc)

Appengine and cloud functions are my favorite services on GCP. In fact is where I have my strong experience. So, if you have any particular question please feel free of reaching me out to handerson.contreras@gmail.com.