What Is Compute Engine?
Google Compute Engine (GCE) is GCP's Infrastructure-as-a-Service offering: it lets you rent virtual machines (called instances) that run on Google's physical hardware, giving you root-level control over the OS, installed software, and runtime configuration. Unlike fully managed platforms such as Cloud Run or App Engine, Compute Engine hands you the raw VM, so you are responsible for patching the OS, managing processes, and scaling capacity yourself, in exchange for maximum flexibility to run any workload, including legacy applications, custom kernels, or GPU-heavy simulations.
Cricket analogy: It's like a franchise in the IPL auction picking its own untested overseas player rather than using a BCCI-contracted all-rounder from the central pool — you get full control over how the player (VM) trains and performs, but the fitness management (OS patching) is entirely on you.
Machine Types and Custom Machine Types
Every Compute Engine instance runs on a machine type that defines its vCPU count and memory. Predefined families include E2 (cost-optimized, general purpose), N2/N2D (balanced price-performance), C2/C3 (compute-optimized for CPU-bound workloads), and M2/M3 (memory-optimized for in-memory databases like SAP HANA). If none of the fixed ratios fit your workload, custom machine types let you specify an exact vCPU-to-memory combination, avoiding the cost of paying for memory or CPU you don't need.
Cricket analogy: Choosing E2 versus C2 is like picking Ravindra Jadeja, a balanced all-rounder, versus Jasprit Bumrah, a pure strike bowler brought in only when raw pace matters most — you pick the machine type to match the specific over you need bowled.
Persistent Disks, Images, and Snapshots
Compute Engine instances boot from a persistent disk, a network-attached block storage volume that survives independently of the VM's lifecycle. Disk types include Standard (HDD-backed, cheapest), Balanced PD, SSD PD, and Extreme PD, trading cost against IOPS and throughput. Images are the templates used to create boot disks — public images (Debian, Ubuntu, Windows Server) or custom images you build from a configured instance — while snapshots are incremental, point-in-time backups of any disk that you can use for backup, disk cloning, or migrating data between regions.
Cricket analogy: A persistent disk is like a player's personal training history that follows them across IPL franchises even after a trade, while a snapshot is like a mid-season fitness report captured before a crucial Eden Gardens semi-final.
Networking and Firewall Rules
Every Compute Engine instance attaches to a VPC network and subnet, receiving an internal IP for private communication and, optionally, an ephemeral or static external IP for internet access. Traffic to and from instances is governed by VPC firewall rules, which are stateful, apply at the network level (not per-instance), and are evaluated by priority — a rule allowing ingress on TCP port 22 from a specific source range is a common example for enabling SSH access without exposing the instance to the entire internet.
Cricket analogy: Firewall rules are like a stadium's security perimeter at the Wankhede — an internal pass (internal IP) gets you into the dressing room, while a public gate pass (external IP) is only issued and checked against a specific allow-list of ticket holders.
# Create a Compute Engine VM with a custom machine type and a balanced persistent disk
gcloud compute instances create web-server-1 \
--zone=us-central1-a \
--custom-cpu=4 \
--custom-memory=8GB \
--image-family=debian-12 \
--image-project=debian-cloud \
--boot-disk-type=pd-balanced \
--boot-disk-size=50GB \
--tags=http-server
# Allow inbound SSH only from a trusted CIDR range
gcloud compute firewall-rules create allow-ssh-office \
--network=default \
--direction=INGRESS \
--action=ALLOW \
--rules=tcp:22 \
--source-ranges=203.0.113.0/24Preemptible VMs and Spot VMs run at up to a 60-91% discount versus on-demand pricing because Google can reclaim the capacity at any time with short notice (30 seconds for preemptible, no guaranteed notice for Spot). They're ideal for fault-tolerant, stateless batch jobs, but never for workloads that can't tolerate sudden termination.
Deleting an instance by default also deletes its boot disk unless you explicitly set the disk's auto-delete flag to false. If you need the disk to survive instance deletion, verify this setting before terminating production VMs — accidental data loss from this default is a common beginner mistake.
- Compute Engine provides IaaS virtual machines with full control over the OS and installed software.
- Machine type families (E2, N2, C2, M2) trade off cost, general-purpose balance, and CPU or memory optimization.
- Custom machine types let you specify exact vCPU and memory ratios when predefined types don't fit.
- Persistent disks are network-attached block storage that outlive the VM; disk type (Standard, Balanced, SSD, Extreme) affects IOPS and cost.
- Images are templates for boot disks; snapshots are incremental, point-in-time backups usable for cloning or migration.
- VPC firewall rules are stateful, evaluated by priority, and control ingress/egress independent of individual instance configuration.
- Preemptible and Spot VMs offer steep discounts for interruptible workloads but can be reclaimed by Google at any time.
Practice what you learned
1. Which machine type family is best suited for a CPU-bound batch rendering workload with modest memory needs?
2. What happens by default when you delete a Compute Engine instance?
3. What is the primary trade-off of using a Spot VM instead of a standard on-demand instance?
4. Which statement about VPC firewall rules is correct?
5. What is the main purpose of a custom machine type?
Was this page helpful?
You May Also Like
Instance Groups and Autoscaling
Understand how Managed Instance Groups keep fleets of Compute Engine VMs healthy and scale them automatically based on load.
Google Kubernetes Engine Basics
Learn the fundamentals of GKE, Google's managed Kubernetes service, including clusters, nodes, workloads, and Autopilot mode.
Cloud Run Basics
Learn how Cloud Run runs stateless containers as fully managed, autoscaling, pay-per-request services on GCP.