Bird
Raised Fist0
GCPcloud~20 mins

Preemptible and Spot VMs in GCP - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Spot and Preemptible VM Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Behavior of Preemptible VMs on GCP

What happens to a Google Cloud preemptible VM when Google needs the resources back?

AThe VM is terminated with a 30-second preemption notice and cannot be restarted.
BThe VM is stopped and can be restarted later manually.
CThe VM is paused and resumes automatically when resources are free.
DThe VM is migrated live to another host without downtime.
Attempts:
2 left
💡 Hint

Think about how preemptible VMs are designed for cost savings but with limited availability.

Architecture
intermediate
2:00remaining
Best Use Case for Spot VMs

Which workload is best suited to run on Google Cloud Spot VMs?

AA critical database server requiring high availability.
BA web server handling live user traffic with low latency needs.
CA stateful application storing user session data.
DBatch processing jobs that can be restarted if interrupted.
Attempts:
2 left
💡 Hint

Consider the interruption nature of Spot VMs and which workloads tolerate it.

security
advanced
2:00remaining
Security Implications of Using Preemptible VMs

Which security risk is most relevant when using preemptible VMs in Google Cloud?

AIncreased risk of VM hijacking due to longer uptime.
BData loss due to unexpected VM termination without shutdown.
CExposure to network attacks because preemptible VMs bypass firewalls.
DAutomatic disabling of encryption on preemptible VM disks.
Attempts:
2 left
💡 Hint

Think about what happens when a preemptible VM is stopped abruptly.

Best Practice
advanced
2:00remaining
Handling Spot VM Interruptions Gracefully

What is the best practice to handle interruptions of Spot VMs in Google Cloud?

AUse a shutdown script to save state and shut down cleanly on interruption notice.
BDisable automatic updates to prevent VM restarts during Spot interruptions.
CManually monitor VM status and restart interrupted VMs yourself.
DIgnore interruptions since Spot VMs never send warnings before termination.
Attempts:
2 left
💡 Hint

Spot VMs provide a short warning before termination. How can you use that?

🧠 Conceptual
expert
2:00remaining
Difference Between Preemptible and Spot VMs

Which statement correctly describes a key difference between Google Cloud Preemptible VMs and Spot VMs?

ASpot VMs cannot be used with managed instance groups; Preemptible VMs can.
BSpot VMs are always cheaper than Preemptible VMs and never get interrupted.
CPreemptible VMs have a fixed maximum runtime of 24 hours; Spot VMs do not have a fixed maximum runtime.
DPreemptible VMs support live migration; Spot VMs do not.
Attempts:
2 left
💡 Hint

Consider runtime limits and interruption behavior differences.

Practice

(1/5)
1. What is the main advantage of using Preemptible or Spot VMs in Google Cloud?
easy
A. They offer unlimited storage capacity
B. They provide guaranteed uptime for critical applications
C. They cost less but can be stopped at any time
D. They automatically scale without user input

Solution

  1. Step 1: Understand the cost and availability trade-off

    Preemptible and Spot VMs are cheaper because Google can stop them anytime to reclaim resources.
  2. Step 2: Identify the main benefit

    The main benefit is cost savings with the risk of interruption, not guaranteed uptime or unlimited storage.
  3. Final Answer:

    They cost less but can be stopped at any time -> Option C
  4. Quick Check:

    Cost savings with interruptions = D [OK]
Hint: Cheaper VMs can be stopped anytime, so cost saving is main benefit [OK]
Common Mistakes:
  • Thinking they guarantee uptime
  • Assuming they scale automatically
  • Confusing with storage features
2. Which of the following is the correct way to specify a Spot VM in a Google Cloud VM creation command?
easy
A. gcloud compute instances create my-vm --spot
B. gcloud compute instances create my-vm --interruptible
C. gcloud compute instances create my-vm --preemptible
D. gcloud compute instances create my-vm --ephemeral

Solution

  1. Step 1: Recall the flag for Spot VMs

    Spot VMs use the flag --spot in the gcloud command.
  2. Step 2: Differentiate from Preemptible flag

    --preemptible is for older Preemptible VMs, --spot is the newer recommended option.
  3. Final Answer:

    gcloud compute instances create my-vm --spot -> Option A
  4. Quick Check:

    Spot VM flag = --spot [OK]
Hint: Spot VMs use --spot flag, not --preemptible [OK]
Common Mistakes:
  • Using --preemptible for Spot VMs
  • Confusing --interruptible as a flag
  • Using unrelated flags like --ephemeral
3. Consider this snippet of a VM creation command:
gcloud compute instances create test-vm --zone=us-central1-a --spot --machine-type=e2-medium
What will happen if Google Cloud needs the resources back?
medium
A. The VM will automatically migrate to another zone
B. The VM will continue running without interruption
C. The VM will be stopped immediately without warning
D. The VM will receive a 30-second warning before stopping

Solution

  1. Step 1: Understand Spot VM behavior on resource reclamation

    Spot VMs are interruptible but Google Cloud sends a 30-second warning before stopping them.
  2. Step 2: Eliminate other options

    Immediate stop without warning is incorrect; automatic migration does not happen for Spot VMs; uninterrupted running contradicts the interruptible nature.
  3. Final Answer:

    The VM will receive a 30-second warning before stopping -> Option D
  4. Quick Check:

    Spot VMs get 30-second warning before stop = A [OK]
Hint: Spot VMs get 30-second warning before stopping [OK]
Common Mistakes:
  • Assuming immediate stop without warning
  • Thinking Spot VMs migrate automatically
  • Believing Spot VMs never stop
4. You created a VM with the command:
gcloud compute instances create my-vm --preemptible --zone=us-east1-b
But you want to switch to Spot VM instead. What is the correct fix?
medium
A. Add --spot flag without removing --preemptible
B. Replace --preemptible with --spot in the command
C. Change the zone to a Spot-only zone
D. Use --interruptible flag instead of --preemptible

Solution

  1. Step 1: Identify the correct flag for Spot VMs

    Spot VMs require the --spot flag, not --preemptible.
  2. Step 2: Correct the command by replacing flags

    Remove --preemptible and add --spot to switch VM type.
  3. Final Answer:

    Replace --preemptible with --spot in the command -> Option B
  4. Quick Check:

    Switching VM type requires flag replacement = B [OK]
Hint: Remove --preemptible, add --spot to switch VM type [OK]
Common Mistakes:
  • Adding --spot without removing --preemptible
  • Changing zone expecting Spot-only zones
  • Using non-existent --interruptible flag
5. You want to run a batch job that can tolerate interruptions and save costs. Which approach best uses Spot VMs to handle sudden stops and restarts?
hard
A. Design the job to save progress frequently and restart automatically on VM preemption
B. Use Spot VMs without any checkpointing or restart logic
C. Run the job on standard VMs to avoid interruptions
D. Use Spot VMs but disable automatic restarts

Solution

  1. Step 1: Understand Spot VM interruption nature

    Spot VMs can stop anytime, so jobs must handle interruptions gracefully.
  2. Step 2: Choose a strategy to handle interruptions

    Saving progress frequently and restarting automatically ensures job completion despite stops.
  3. Step 3: Eliminate unsafe options

    Running without checkpointing risks data loss; standard VMs cost more; disabling restarts loses fault tolerance.
  4. Final Answer:

    Design the job to save progress frequently and restart automatically on VM preemption -> Option A
  5. Quick Check:

    Checkpointing + auto-restart = reliable Spot VM use [OK]
Hint: Checkpoint progress and auto-restart for Spot VM jobs [OK]
Common Mistakes:
  • Ignoring checkpointing and restart logic
  • Choosing standard VMs for cost savings
  • Disabling automatic restarts on Spot VMs