Compute Virtual Machine Types
Start course
1h 34m

Google Cloud Platform has become one of the premier cloud providers on the market. It offers the same rich catalog of services and massive global hardware scale as AWS as well as a number of Google-specific features and integrations. Getting started with GCP can seem daunting given its complexity. This course is designed to demystify the system and help both novices and experienced engineers get started.

This Course covers a range of topics with the goal of helping students pass the Google Associate Cloud Engineer certification exam. This section focuses on identifying relevant GCP services for specific use cases. The three areas of concern are compute, storage, and networking. Students will be introduced to GCP solutions relevant to those three critical components of cloud infrastructure. The Course also includes three short practical demonstrations to help you get hands-on with GCP, both in the web console and using the command line.

By the end of this Course, you should know all of GCP’s main offerings, and you should know how to pick the right product for a given problem.

Learning Objectives

  • Learn how to use Google Cloud compute, storage, and network services and determine which products are suitable for specific use cases

Intended Audience

  • People looking to build applications on Google Cloud Platform
  • People interested in obtaining the Google Associate Cloud Engineer certification


To get the most out of this course, you should have a general knowledge of IT architectures.


Now, in this lesson, we're going to go over the various types of virtual machines you can launch in Google Cloud Compute Engine. Our emphasis here will be on cost savings and usage, so as we discussed in the previous section, Cloud Compute offers a range of instance types based upon our apps' resource needs, we can also choose from a variety of Linux operating system flavors as well as Windows.

Now, as far as hardware goes, there are three main families of instance types. There are compute-optimized, memory-optimized, and sole tenant. Compute-optimized instances offer the highest performance per core with a range of options going up to instances with four hundred and sixteen virtual CPUs. Now, memory-optimized instances are for memory-intensive workloads. You can get up to several thousand gigs of memory in a single VM if needed, and then finally, there are sole tenant offerings that isolate your VMs and workloads on their own physical servers. So, see the documentation for a more detailed list of the exact instance type names but these are the three basic categories.

Now, by default, your Cloud Compute instances are billed based on uptime. The cost is calculated per second and the price is largely based on the instance type, however, region also plays a factor. So for example, an instance with a lot of memory will cost more than one with very little. Instances in us-east4 Virginia might cost a little more than instances in us-east1, which is South Carolina. Usually, these region price differences are fairly small but it's good to be aware of them. 

Now, so far we've been talking about standard, on-demand instances that are created upon request. There are actually two other types of instances that we need to consider to fully understand Cloud Compute, and these are custom machine types and preemptable VMs. So, let's start with the former. Custom machine types. Now, even though GCP, Google Cloud Platform, it offers a wide variety of Linux operating systems and Windows VM types, sometimes we want to get really specific about memory and CPU configuration for our workload. So for example, we may find that GCP's high-memory instance types have more CPU than we need or vice versa. Maybe we need a lot of CPU and little memory. With the custom machine type option you can actually specify the exact amount of memory and the exact amount of virtual CPUs, provided it's an even number. You need an even number, of course. Now, you can do this with a single command. Here's an example here at gcloud compute instances create my VM you just do - - custom CPU - - custom memory.

There are many different operating systems that are compatible with the custom machine type API. You can pick Debian, CentOS, OpenSUSE, Ubuntu. Windows is also an option, whether via the console or the command-line. Custom machine types are straightforward to set up and launch for workloads that need them. Now, we should talk a bit about preemptable VMs, these are very interesting, these are actually short-lived VM instances that run for up to 24 hours at a time. Now the upside, because they're so short-lived, is that they are extremely cheap—to 80 percent less than a regular VM.

Now, the downside here is that they are not suitable for any kind of fault-tolerant workload. With preemptable instances, you don't know when they might die. They're guaranteed to shut down within 24 hours, you can create a managed instance group of preemptable VMs if you want to try to keep a certain number up and running, however, the thing is, preemptable VMs come from excess GCP Compute capacity so because of that, there's no guarantee that a certain number of preemptable VMs will be available, particularly if you need a specific type.

So, you know, for example, you might have a managed instance group of 30 preemptable VMs and maybe they'll run for a while, but if there's not sufficient capacity in that GCP region you may be down to only 20 instances for a while, you might just lose ten of them and because of the inability to guarantee availability, preemptable VMs are not appropriate for any use case that requires consistent uptime or stability. They're great for batch processing, short jobs that can tolerate instances coming and going. And also note that preemptable instances are available for predefined instances and for the custom machine types that we talked about a minute ago.

By combining a custom machine type with a preemptable VM you can really optimize your costs for fault-tolerant jobs. Preemptable VMs are not the only method for controlling costs, there are actually two other really important discount options available on GCP. These are sustained use discounts and committed use discounts. Now, the latter, as the name implies (committed use), is a discount for paying for a certain amount of usage time upfront. This is similar to like Amazon reserved instances. With committed use contracts, you can pay upfront for one year or three years of compute service and get a discount of 50 to 70% of the cost and actually when I say pay upfront, you don't actually pay the full year or three years cost right away, the billing is actually still done monthly so you don't have to worry about some huge you know three years of compute paying upfront. You pay monthly and, you know, if you stop using the instance after six months, you'll still get billed for the full year, but it's still a really great option if you can actually plan ahead with your infrastructure and you know that something's gonna run for a year or two years this is the way to save money and so because, you know, you get a 50 to 70% discount.

So on top of that, there's also something called a sustained use discount. Sustained use discounts, these kick in automatically if you run a VM instance for a certain percentage of time over the course of a month. So, for example, you can get a price cut of around 10% if you run an instance for more than 25 percent of the month and if you run that same instance for 100 percent of the month with no break, you can get up to a 30 percent discount in the cost.

Now, I'm using a little bit of imprecise language, this is kind of rough amounts because the exact discount varies a lot by instance type, but in general, the more you run your instances the bigger the discount. Sustained use discounts are really great because you don't have to think about them at all. They apply to custom machine types as well and they kick in automatically. Now, the only exception, the only instances that do not get sustained use discounts are App Engine flexible environment instances and also Cloud Dataflow VMs. Very specific, if you use Cloud Dataflow it's not applicable for sustained use discounts. So with this combination of preemptable VMs with sustained use discounts with committed use discounts, you have three really good ways to save money on GCP.

Consider your workload to identify which is best for you, you only need compute instances for very very small periods of time, if so, definitely go with the preemptable VMs. Very, very cheap. If, by contrast, you know for certain that your instances have to run for a year or longer, then the committed user discounts can cut your bill in half, no additional upfront cost and if you can be certain of either of these scenarios or well actually no, if you can't be certain of either of these scenarios, well then take solace in the fact that there are automatic sustained use discounts that kick in, you know, without any effort or decision-making on your end. So we will stop there.

You should now have a good grounding of GCP instance types and cost optimization. Congrats. Now, to help you save even more, we'll go over the GCP price calculator tool in the next lesson. See you there!

About the Author

Jonathan Bethune is a senior technical consultant working with several companies including TopTal, BCG, and Instaclustr. He is an experienced devops specialist, data engineer, and software developer. Jonathan has spent years mastering the art of system automation with a variety of different cloud providers and tools. Before he became an engineer, Jonathan was a musician and teacher in New York City. Jonathan is based in Tokyo where he continues to work in technology and write for various publications in his free time.