Back to Library
gcp

Compute Engine - Virtual Machines

Compute Engine provides virtual machines on Google's infrastructure. You choose machine type, OS, and pay per second with sustained-use discounts applied automatically.

gcpcomputevmsscaling

What is Google Compute Engine?

Compute Engine is GCP's IaaS virtual machine service. Like EC2 on AWS, each instance is a virtual server running on Google's global infrastructure. You pick a machine type, a boot disk image, and a region/zone.

Key differentiator: Google applies sustained use discounts automatically - no reservations needed. Use a VM for 25%+ of a month and discounts kick in, reaching up to 30% for full-month usage.

Machine Types

GCP organises machine types into families:

FamilyOptimised ForExample
E2Cost-optimised generale2-standard-4
N2 / N2DBalanced generaln2-standard-8
C2 / C3Compute-optimised (high clock speed)c2-standard-16
M1 / M2 / M3Memory-optimised (up to 12 TB RAM)m2-ultramem-208
A2 / A3GPU-accelerated (NVIDIA)a2-highgpu-1g
T2DScale-out AMD EPYCt2d-standard-32

You can also create custom machine types - specify exact vCPU and RAM without being locked to a preset. Useful for right-sizing.

Pricing Models

ModelDescriptionSavings
On-demandPay per second, no commitmentBaseline
Sustained useAuto-discount for sustained usage in a monthUp to 30%
Committed use (1 or 3 yr)Commit to resources in a regionUp to 57%
Spot VMsInterruptible, can be reclaimed by GoogleUp to 91%
Preemptible (legacy)Older spot model, max 24hr lifetimeUp to 80%

Disks

  • Persistent Disk (PD): network-attached, survives instance stop/delete (if not auto-deleted). Types: pd-standard (HDD), pd-balanced (SSD), pd-ssd (high IOPS), pd-extreme (highest IOPS, manual provisioning).
  • Local SSD: NVMe attached directly to the physical host. Extremely fast (~2.4M IOPS). Ephemeral - data lost on instance stop.
  • Hyperdisk: next-gen network-attached storage. Decouple capacity from IOPS/throughput - provision exactly what you need.

Instance Groups

  • Managed Instance Group (MIG): fleet of identical VMs from an instance template. Supports autoscaling, auto-healing (recreates unhealthy instances), rolling updates, and multi-zone deployment.
  • Unmanaged Instance Group: arbitrary set of VMs behind a load balancer - no autoscaling.

MIGs are the GCP equivalent of AWS Auto Scaling Groups.

Live Migration

Google's hypervisor can live migrate a running VM to different hardware during maintenance - no downtime. AWS restarts instances for host maintenance. This is a significant operational advantage for stateful workloads.

Metadata Server

Every instance can reach metadata.google.internal (169.254.169.254) to get instance metadata, project metadata, and service account credentials. The Compute Engine default service account issues short-lived tokens automatically - no key files needed.

Interview Angle

Compute Engine questions focus on: machine type selection (custom types for right-sizing), pricing (sustained use discounts vs committed use vs Spot), MIGs for HA and autoscaling, and live migration as a GCP differentiator. For stateless web tiers - MIG + HTTP(S) Load Balancer. For databases - persistent disk with pd-ssd, consider regional PD for synchronous replication across two zones.

Recommended Resources