Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Virtual Machine Provisioning Service

Launch virtual machines on a shared fleet of physical hosts: pick a host without giving its capacity away twice, build the VM's disk and network on that host, start it through the hypervisor, and clean up everything when a launch fails or the VM is terminated.

Problem statement

For this exercise, assume a public cloud lets customers launch virtual machines (VMs) in a region. A customer picks one of the region's three availability zones, a shape that fixes the number of virtual CPUs (vCPUs) and the amount of memory, a boot image, and a subnet of their virtual network.

The launch call returns at once with an instance ID, and the customer then follows the VM through its lifecycle until it is running or has failed with a reason. A customer can also terminate a VM.

Design the service that provisions these VMs. It chooses a physical host for each VM, makes sure no host's capacity is handed out twice, gets the VM's boot disk, network interface and VM definition set up on that host, starts the VM, and cleans everything up when a launch fails or a VM is terminated.

For this exercise, assume each host runs a hypervisor and a small agent that your service controls. Images are immutable and kept in a regional object store, and each host has local disks for VM boot disks.

An existing virtual network service owns subnets, hands out private IP addresses and programs the virtual switch on each host; your service calls it but does not design it.

Running means the hypervisor has started the VM with its boot disk and network interface attached; whether the customer's operating system then boots correctly is outside this promise. Hosts never overcommit vCPUs or memory.

Stopping and restarting, resizing, live migration, extra data volumes, billing and console access are out of scope.

What to build

  1. A customer can launch a VM by choosing a zone, shape, image and subnet with an idempotency token, gets an instance ID right away, and can follow the VM until it is running or has failed with a reason.
  2. Each VM is placed on a healthy host in the chosen zone that has room for its shape, and the same host capacity is never given to two VMs.
  3. A placed VM gets a boot disk made from the chosen image and a network interface with a private IP in the chosen subnet, and is started on its host.
  4. A customer can terminate a VM, and terminating it or failing a launch releases its host capacity, boot disk, network interface and IP address, so nothing is left behind.

At scale

  • For this exercise, assume one region with three availability zones and about 30,000 hosts, 10,000 per zone. Each host has 128 vCPUs, 1 TB of memory and a few terabytes of local disk, and the fleet is usually about 80 percent allocated.
  • For this exercise, assume shapes range from 1 to 64 vCPUs with 4 to 16 GB of memory per vCPU and at most 512 GB per VM, about 400,000 VMs are running, and launches average about 5 a second with bursts of up to 300 a second when one customer starts thousands of VMs at once.
  • For this exercise, assume 95 percent of launches should reach running within 60 seconds of the launch call, and the launch call itself should return within one second.
  • For this exercise, assume images are typically 10 GB and at most 50 GB, about 50 images account for most launches, one host can download an image at about 1 GB per second, and the regional image store can serve about 200 GB per second in total.