Prepare and test your skills
Prepare and test your skills
Cost Optimization and Provisioning Architecture is the practice of mixing stable and volatile compute capacity to lower cost without breaking performance. In Compute Engine, standard VMs use the standard provisioning model with stable capacity and on-demand pricing, while Spot VMs (opens in a new tab) use the spot provisioning model with excess capacity at deep discounts and preemption risk. A balanced architecture keeps critical work on standard VMs and puts fault-tolerant work on Spot VMs in the same environment.
Standard and Spot pricing models differ in cost, capacity assurance, and lifecycle stability. Standard VMs are charged at standard on-demand rates while resources are in use and run until you stop or delete them, with no preemption. Spot VMs are also charged only while resources are in use, but they receive automatic spot discounts of up to 91% on vCPUs, memory, GPUs, and attached Local SSD disks compared to on-demand prices.
| Model | Pricing | Capacity and lifecycle |
|---|---|---|
| Standard VMs | Standard on-demand rates, pay as you go when in use | Immediate creation based on availability, runs until stopped or deleted, very high assurance when paired with reservations |
| Spot VMs | Deeply discounted up to 91%, pay as you go when in use | Best-effort availability from excess capacity, can be stopped by default or deleted at any time, no Service Level Agreement (SLA) |
Spot VMs offer the same machine types, options, and performance as standard VMs while they run. Premium operating system licenses are not discounted, Spot VMs cannot live migrate to become standard VMs, and Spot VMs cannot automatically restart on a host event.
Preemption is the process where Compute Engine reclaims Spot VM capacity at an uncertain time for reasons such as system events. The probability of preemption is generally low but varies by day and zone, and availability varies because Spot VMs depend on unused Compute Engine capacity. When preemption occurs, the Spot VM moves from running to stopped or deleted based on its termination action, and local data on the VM is lost.
This volatility makes Spot VMs a fit for stateless, fault-tolerant work that can fail gracefully, such as batch processing, data analytics, distributed training, and media encoding. If some Spot VMs stop during a batch job, the job slows but does not completely stop, and it finishes without paying full price for extra standard VMs. Spot VMs are not a fit for critical production work, stateful applications, or work that needs assured capacity, live migration, or SLA coverage.
Exam tip: Choose Spot VMs when the workload can withstand preemption and has no SLA requirement; choose standard VMs when the workload needs stable capacity, automatic restart, or one-hour maintenance notice for GPUs.
A mixed provisioning architecture keeps a stable base on standard VMs and adds volatile capacity on Spot VMs to balance budget and resilience. In Google Kubernetes Engine (GKE), the cluster depends on separate node pools, so critical Pods run on a standard node pool and burstable or batch Pods run on a Spot node pool. In a managed instance group (MIG), the group depends on an instance template and repeatedly tries to maintain its target size or autoscaler size, so the MIG recreates stopped Spot VMs from the template when resources become available again.
To build a resilient mixed environment, apply these provisioning strategies:
When zone capacity is limited, a MIG may be unable to scale out Spot VMs to its target size until capacity returns, so the standard base ensures work continues during stock-outs.
Special costs and quotas for Spot VMs determine the true savings for storage, accelerator, and license-heavy designs. Local SSD disks attached to Spot VMs are billed at spot prices, work like normal Local SSD disks, and stay attached for the life of the VM, but Compute Engine does not charge for them if the VM is preempted in the first minute. GPUs attached to Spot VMs are billed at lower spot prices and persist only for the life of the VM, and Compute Engine does not charge for GPUs if the VM is preempted in the first minute. Premium operating systems follow a different rule: Spot VMs do not reduce premium license cost, minimum-usage charges still apply, and machine types with premium images are billed by the second.
Spot VMs consume CPU, disk, and GPU quota, and without dedicated preemptible quota they consume standard quota for those resources. Requesting preemptible quota, including Preemptible GPU quota, prevents Spot VMs from consuming the quota needed for standard VMs. Spot VMs also have hard limits: they do not support A4X machine series or bare metal instances, Google Cloud Free Tier credits do not apply to them, and additional limits apply to TPU Spot VMs.
Operational Characteristics and Workload Suitability describe how standard VMs and Spot VMs (opens in a new tab) differ in lifecycle, availability, and fit for different applications. Standard VMs use the standard provisioning model to run until you stop or delete them, while Spot VMs use the spot provisioning model to run on excess Compute Engine capacity at discounts of up to 91%. Because Compute Engine can reclaim Spot VMs at any time, standard VMs suit stable and mission-critical work and Spot VMs suit fault-tolerant work that can handle interruption.
Standard VMs are on-demand instances with a stable lifecycle and best-effort to high-assurance availability. A standard VM runs continuously until you stop or delete it, and it remains available for immediate creation based on capacity without waiting for scheduling or approval. During a host event such as planned hardware maintenance, Compute Engine keeps a standard VM running by performing a live migration of the VM to another host in the same zone. You can also control how the VM responds to maintenance or errors by setting a host maintenance policy, including automatic restart, which preserves uptime for non-clustered and stateful applications.
Spot VMs are excess Compute Engine capacity with a preemptible lifecycle and no availability guarantees. A Spot VM has no minimum or maximum runtime and stays in the running state until Compute Engine preempts it to reclaim capacity; at that uncertain time, Compute Engine either stops the VM by default or deletes it based on the termination action you configure. Spot VMs are finite resources that might not always be available, and the probability of preemption is generally low but varies by day and by zone. Spot VMs cannot live migrate to become standard VMs while running, cannot automatically restart on a host event, are not covered by any Service Level Agreement (SLA), and are excluded from the Compute Engine SLA.
Spot VM preemption has direct operational consequences for storage, networking, and orchestration. Data on the node is deleted when Compute Engine preempts the instance, and attached Local SSD disks do not persist after deletion and remain attached only for the life of the VM. While node names usually stay the same after recreation, internal and external IP addresses might change. In Google Kubernetes Engine (GKE) (opens in a new tab) (formerly Google Kubernetes Engine), reclamation of Spot VMs is involuntary and is not covered by the guarantees of PodDisruptionBudgets, so you might experience greater unavailability than your configured budget.
Exam tip: Standard VMs support live migration and automatic restart during host events, while Spot VMs are preempted instead and have no SLA protection.
Matching workloads to volatility means placing fault-tolerant, stateless, and batch work on Spot VMs and keeping mission-critical work on standard VMs. Spot VMs offer the same machine types, options, and performance as regular VMs while running, so a batch processing job slows but does not completely stop if some Spot VMs are preempted. A managed instance group (MIG) depends on available capacity to maintain its target size, so the group repeatedly tries to recreate preempted Spot VMs from its instance template and succeeds only after resources become available again.
Choose Spot VMs when the workload can fail gracefully and resume without data loss:
Choose standard VMs when the workload requires continuity, capacity assurance, or state preservation:
When mixing both models in GKE, the cluster depends on standard node pools for stability and Spot node pools for cost savings. Keep at least one non-GPU standard node pool before adding a GPU Spot node pool, maintain a mix of Spot and standard pools so jobs continue when Spot capacity is unavailable, and use node taints and tolerations so critical Pods are not scheduled onto Spot nodes. To run stateful work on Spot VMs, test that workloads can gracefully terminate within 25 seconds of shutdown to minimize risk of persistent volume data corruption.
| Model | Lifecycle and maintenance | Availability guarantee | Choose when |
|---|---|---|---|
| Standard VMs | Runs until stopped or deleted; supports live migration and automatic restart | Best-effort creation, very high assurance with reservations; covered by SLA | Workload is mission-critical, stateful, or must survive maintenance |
| Spot VMs | Runs until preempted, then stopped or deleted; no live migration or automatic restart | Best-effort with no guarantees; can be reclaimed at any time | Workload is fault-tolerant, stateless, or batch-based and can retry after preemption |
Preemption Handling and Resilience Strategies explain how to keep fault-tolerant work moving when excess capacity is reclaimed. Spot VMs (opens in a new tab) are excess Compute Engine capacity offered at discounts of up to 91% with no guarantee of availability. Compute Engine can preempt Spot VMs at any time to reclaim capacity for other tasks, either stopping the VM by default or deleting it based on its termination action.
Spot VM preemption ends the running VM when Compute Engine needs the underlying capacity for system events or higher-priority demand. The probability of preemption is generally low but varies by day and by zone, and Spot VMs are finite resources that might not always be available for restart. A preempted Spot VM follows its configured termination action, either stopped so its disks and configuration remain for a later restart, or deleted so the VM and its local resources are removed.
Spot VMs cannot live migrate to another host during maintenance and cannot automatically restart after a host event, unlike standard VMs. A preempted Spot VM stays stopped or deleted until something recreates or restarts it, and local data such as Local SSD disks is lost on deletion. Batch processing is a classic fit because losing some workers only slows the job instead of stopping it completely.
Handling preemption means running cleanup code during the short window between the preemption signal and final shutdown, such as stopping a process gracefully and uploading a checkpoint file to Cloud Storage. Spot VMs support two handling patterns that depend on the configured preemption notice duration. The default configuration has no notice period and relies on a shutdown script that runs for up to 30 seconds on a best-effort basis, while the 120-second option gives workload code time to react before shutdown begins.
A typical shutdown script finds the running program, sends it a termination signal such as SIGINT, waits for it to exit, and then copies a checkpoint file to a Cloud Storage bucket with gcloud storage cp. The script assumes the VM has Cloud Storage access and that the checkpoint captures enough state to resume work elsewhere. After the script finishes or times out, the operating system kills any remaining processes and Compute Engine completes the stop or delete action.
| Handling option | Notice configuration | Where cleanup code runs |
|---|---|---|
| Shutdown script handling | 0s, the default with no notice period | Cleanup code runs in a shutdown script during the best-effort shutdown period of up to 30 seconds |
| In-workload handling | 120s preemption notice duration | Cleanup code in the workload waits for preemption to start, runs during the notice period, with an optional shutdown script afterward |
Exam tip: The default Spot VM has a 0s notice duration and a STOP termination action, so cleanup must be in a shutdown script unless you explicitly enable the 120-second notice to handle preemption inside the workload.
Detecting preemption lets automation distinguish a preemption shutdown from an ordinary reboot or guest-initiated stop. Inside the VM, code can poll for the preemption signal so cleanup runs only when the VM is actually being preempted and exits immediately otherwise. Outside the VM, operators can list system operations for a project and zone and filter for preemption operations, optionally adding a target filter for one VM name to see its preemption history with status DONE and message Instance was preempted.
Testing preemption verifies that detection and cleanup work before a real capacity event occurs. Simulated maintenance events force a Spot VM to preempt on demand, so teams can confirm that checkpoints upload, processes exit cleanly, and replacement capacity starts correctly. This test is especially important for stateful work on Spot VMs, where GKE guidance is to prove graceful termination within about 25 seconds to reduce the risk of persistent volume corruption.
Managed Instance Groups (MIGs) are the primary infrastructure control for staying available through preemption events. A MIG is built from an instance template and continuously tries to hold its target size or autoscaler size, so when Compute Engine stops Spot VMs in the group, the MIG repeatedly attempts to recreate them from the template once capacity returns. Because MIGs depend on available zone capacity, they cannot resize or autoscale Spot VMs while resources remain limited.
Resilience increases when the MIG can choose from more capacity options:
For Google Kubernetes Engine (GKE) (opens in a new tab), the same principle means mixing node pools that use Spot VMs with node pools that use standard Compute Engine VMs so jobs still schedule when Spot capacity is gone. Node taints and tolerations keep critical Pods off Spot node pools, while fault-tolerant batch Pods tolerate reclamation even though involuntary reclamation is not covered by PodDisruptionBudgets. Checking real-time Spot VM availability and historical preemption rates and pricing before creation further reduces surprise preemptions and failed scheduling.
Standard VMs use the standard provisioning model with stable capacity at on-demand rates and run until stopped or deleted with no preemption, live migration and automatic restart support, and Service Level Agreement (SLA) coverage. Spot VMs use excess capacity at discounts of up to 91% on vCPUs, memory, GPUs and attached Local SSD disks with best-effort availability, no SLA, no live migration or automatic restart, and can be stopped by default or deleted at any time. Spot VMs offer the same machine types, options and performance as standard VMs while they run, but premium operating system licenses are not discounted.
Use Spot VMs for fault-tolerant, stateless work that can fail gracefully and resume without data loss, such as batch processing, data analytics, distributed training and media encoding. Keep mission-critical, stateful or latency-sensitive work on standard VMs when it needs stable capacity, automatic restart, live migration or SLA coverage. If some Spot VMs stop during a batch job, the job slows but does not completely stop.
When Compute Engine reclaims capacity, a Spot VM moves from running to stopped by default or deleted based on its termination action and local data on the VM is lost. The default configuration uses a 0s notice duration with cleanup in a shutdown script during a best-effort shutdown period of up to 30 seconds, while the 120-second notice option lets workload code react before shutdown begins with an optional shutdown script afterward. A managed instance group (MIG) built from an instance template then repeatedly tries to recreate preempted Spot VMs to hold its target size once zone capacity returns.
A mixed architecture keeps a stable base on standard VMs for critical, stateful or latency-sensitive work and adds Spot VMs only for extra or batch capacity so work continues during stock-outs. In Google Kubernetes Engine (GKE), critical Pods run on a standard node pool and burstable or batch Pods run on a Spot node pool, with at least one non-GPU standard node pool before adding a GPU Spot pool and node taints and tolerations so critical Pods are not scheduled onto Spot nodes. In a managed instance group (MIG), the group depends on an instance template and repeatedly tries to maintain its target size or autoscaler size, so it recreates stopped Spot VMs from the template when resources become available again.
An enterprise organization is architecting a multi-tier application environment on Google Cloud with the following workload profiles:
You need to choose the appropriate Compute Engine VM provisioning model for each workload to optimize cost efficiency while meeting operational availability requirements.
Which compute configuration should you recommend?
Last updated