What it is
A virtual machine (VM) is a computer implemented in software on top of a real one. A hypervisor runs on the physical host and gives each VM virtual CPUs, memory, disks and network interfaces. Each VM boots its own operating system kernel and runs as if it had the hardware to itself. Cloud "instances" (EC2, Compute Engine, Azure VMs) are VMs; the provider's hypervisor and control plane decide which physical host each one lands on.
Why it exists
Physical servers are expensive, slow to buy and usually underused. Virtualisation lets one machine run many independent workloads safely: different customers, different operating systems, different kernels. You get a machine in minutes through an API, resize or replace it without touching hardware, and pay for what you run. For providers, packing many VMs onto large hosts is what makes the cloud economical.
How it works
Hypervisor. Type-1 hypervisors (KVM, Xen, Hyper-V, ESXi) run directly on the hardware, or as part of the host kernel in KVM's case. Hardware virtualisation extensions (Intel VT-x, AMD-V, and second-level address translation for memory) let guest code run directly on the CPU at near-native speed; the hypervisor steps in only for privileged operations. Major clouds offload networking and storage virtualisation to dedicated cards so that more host CPU is left for guests.
vCPU scheduling. A vCPU is a thread the hypervisor schedules onto a physical core (on x86 clouds usually one hardware thread, i.e. half a core with SMT). If the host has more runnable vCPUs than hardware threads, some wait. The guest sees that waiting as steal time (st in top, steal in /proc/stat).
Isolation. Each VM has its own kernel and address space; a guest kernel panic, a root compromise inside a guest, or a full guest disk stays inside that VM. This boundary is strong enough that providers put unrelated customers on the same host. It does not partition everything: last-level caches, memory bandwidth, local disks and network links are shared, which is where noisy neighbours come from.
Instance types. You pick a size from a catalogue: vCPUs, memory and sometimes local disk, network bandwidth and accelerators, grouped into families (general purpose, compute-, memory-, storage-optimised). Burstable families give a baseline CPU share plus credits for short bursts.
Lifecycle. Launching a VM means: allocate a host, attach a disk created from an image, boot the guest OS, run start-up scripts, start the application, pass health checks. Expect tens of seconds to a few minutes, depending on image size and what the app does at start-up. Changing the instance type on most clouds requires stopping the VM and starting it again.
When to use it
- You need a full OS you control: kernel modules, specific kernels, system services, or software that expects a whole machine.
- Strong isolation between tenants or trust levels.
- Long-running, stateful services (databases, brokers) where boot time does not matter much.
- As the host for containers: most Kubernetes nodes are VMs.
When not to
- Short, bursty work where boot time dominates: containers or functions start much faster.
- Many small services on one machine: a guest OS per service wastes memory and patching effort.
- When you would rather not manage an OS at all: managed services or serverless.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| VM instead of container | Own kernel, stronger isolation | Boot time, memory per guest OS, OS patching per VM |
| Scale up (bigger type) | One machine, no distribution | Restart to resize; hard ceiling; single point of failure |
| Scale out (more VMs) | No resize outage, survives a host failure | Load balancer, boot time for each new VM, more to operate |
| Burstable type | Cheap for mostly idle workloads | Throttled when credits run out |
| Dedicated host | No other tenants on your hardware | Higher cost, you manage host capacity |
Alternatives
- Containers: share the host kernel, start in well under a second to a few seconds, much less overhead; weaker isolation boundary.
- MicroVMs (Firecracker, Cloud Hypervisor): VM isolation with a minimal device model, booting in a fraction of a second; used under serverless platforms and sandboxed container runtimes.
- Bare metal: no hypervisor overhead or neighbours; slowest to provision and resize.
- Serverless functions: no machine to size at all, at the cost of limits on runtime and state.
Failure modes
- Undersized instance: CPU saturates, queues grow, then requests are rejected or time out.
- Resize outage: a single VM resized in place is down for the restart.
- Slow scale-out: new VMs arrive after allocation, boot and health checks; the existing fleet must survive that window.
- Noisy neighbour: another tenant's load raises your latency through CPU steal or shared caches, memory bandwidth, disk or network. The guest's own CPU graph may look normal.
- Host failure or maintenance: all VMs on a host are affected together. Clouds live-migrate many VMs for planned maintenance, but hardware failures still restart them elsewhere.
- Burst credit exhaustion: a burstable VM is fine for hours, then is throttled to its baseline.
In production
Run at least two VMs per tier behind a balancer, spread across hosts and zones (placement groups or spread policies). Bake images (golden images, Packer) so boots do less work. Monitor steal time, per-instance latency and errors, not just fleet averages. Prefer replacing VMs to resizing them in place, and keep capacity headroom for the boot time of new instances. Treat VMs as replaceable: configuration in code, data on attached volumes or managed services.
Common misconceptions
- "A vCPU is a core." On most x86 clouds it is one hardware thread; two vCPUs share a physical core.
- "VMs are fully isolated." They isolate faults and security domains well, but share caches, memory bandwidth, disks and networks.
- "Resizing is free." On most clouds it needs a stop and start.
- "A new VM adds capacity immediately." Only after it has booted, started the app and passed health checks; often later still, once caches are warm.
Interview angle
Know what a hypervisor does and how a VM differs from a container (own kernel versus shared kernel). Size instances with arithmetic ("50 ms CPU per request, 8 vCPUs, about 160 req/s at 100%; plan for 60–70%"). Explain why you would scale out rather than up (no resize outage, host failure tolerance) and what limits scale-out speed (boot plus health checks). Mentioning steal time and noisy neighbours when asked about unexplained latency on cloud VMs shows practical experience.
Model assumptions
This lesson uses a simplified model, not a benchmark. A VM is a simulated server whose workers stand for vCPUs; each request needs 50 ms of CPU (lognormal, cv 0.35), so 4 vCPUs serve about 80 req/s and 8 about 160. Arrivals are Poisson. The hypervisor is a scripted illustration: its time-slice tokens are not simulated scheduling. The noisy neighbour is modelled as the Web VM running at half speed, not as cache or memory-bandwidth contention. Boots and resizes are timed actions on a compressed timeline (about a second instead of tens of seconds to minutes). Health checks run every 250 ms; 2 failures eject, 2 successes admit. Utilisation is the fraction of busy vCPUs.