Compute: VMs and serverless
About this lesson
Compute is the processing power that runs your code, and the cloud rents it to you in two common shapes. A virtual machine is a slice of a physical server that you size and manage, billed for every second it is on. A serverless function is just your code: the platform starts copies when requests arrive and removes them when they stop. Follow the same small Python handler through four requests both ways and compare the seconds each one counts.
A computer you rent
Compute means processing power: a CPU and memory that run your code. In the cloud that power sits in physical servers in a provider's data centre. You never touch the machine; you rent a slice of it.
compute = CPU + memory that run your code cloud: real servers in a data centre you rent a slice, on demand the provider owns and fixes the hardware
Read the lesson step by step
A computer you rent
Compute means processing power: a CPU and memory that run your code. In the cloud that power sits in physical servers in a provider's data centre. You never touch the machine; you rent a slice of it.
compute = CPU + memory that run your code cloud: real servers in a data centre you rent a slice, on demand the provider owns and fixes the hardwareOne server, many VMs
A hypervisor is software that splits one physical server into several virtual machines (VMs). Each VM gets its own share of CPU and memory and its own operating system, kept apart from its neighbours.
physical server └ hypervisor ├ your VM: own OS, CPU share, memory └ another VM: own OS, CPU share, memory VMs cannot see each other's memory or filesYour virtual machine
You pick a size, say 2 virtual CPUs (vCPUs) and 4 GiB of memory, then install your app on it. The VM is yours to run: you update its operating system and decide when to add more VMs.
size: 2 vCPU · 4 GiB memory you manage: the operating system and its updates your app (here: the handler) adding VMs when traffic growsAlways on, always billed
Requests arrive now and then; between them the VM sits waiting. It is billed for every second it is switched on, busy or idle. Left on for one hour, that is 3600 seconds, even for just 4 requests.
VM switched on for 1 hour billed: 60 × 60 = 3600 s requests served: 4 per-second billing, 60 s minimum (Amazon EC2 Linux, Google Compute Engine)Serverless: just the code
Serverless turns this around. You upload only a function, like this Python handler, and the provider runs the servers for you. There is no VM to size or update. AWS Lambda is a well-known example.
you upload: def handler(event, context): name = event["name"] return "Hello, " + name the provider runs, sizes and updates the servers underneathThe first request: a cold start
The first request finds nothing running. The platform starts a fresh copy of your function, called an instance: it loads the code, starts Python and runs any set-up code. That extra wait is a cold start.
request 1 → no instance running start instance 1: load the code start Python run set-up code = cold start (extra wait)The handler runs
Now the handler runs. event is the request, {"name": "Ada"}, and it returns "Hello, Ada". Say that takes 0.12 seconds. You pay for run time, counted to the millisecond, plus a tiny fee per request. The cold-start set-up time is billed too.
handler({"name": "Ada"}, context) name = "Ada" → "Hello, Ada" run time: 0.12 s (assumed) billed to the nearest 1 ms (AWS Lambda) + cold-start set-up time, also billedMore requests, more copies
Three requests arrive at once. On AWS Lambda each instance handles one request at a time by default, so the platform starts two more copies, side by side. That is scaling out, and it is automatic. Run time: 4 × 0.12 = 0.48 seconds.
3 requests at the same moment instance 1 (warm) takes one instances 2 and 3 cold-start = scaling out, automatic run time: 4 × 0.12 s = 0.48 sScale to zero
When the requests stop, the instances wait idle for a while, then the platform shuts them down. With no code running, the function is billed nothing for its time. The next request brings a cold start again.
no requests instances idle for a while then shut down: 3 → 0 function run time: still 0.48 s next request → cold startWhich one to choose
Same 4 requests: the VM was billed 3600 seconds; the function ran 0.48, plus cold starts. VMs suit steady or long-running work and full control. Serverless suits short, bursty tasks; one Lambda call can run at most 15 minutes.
VM 3600 s always on, full control function 0.48 s run time (+ 3 cold starts) VM: steady, long-running, custom OS serverless: short, bursty, no servers Lambda limit: 900 s (15 min) per call
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01What does a hypervisor do?
A hypervisor is software that shares one physical server's CPU and memory among several virtual machines, each with its own operating system, kept apart from the others.
02Your VM is switched on for one hour and serves only four requests. How long is it billed for?
A VM is billed for every second it is on, busy or idle. Amazon EC2 (Linux) and Google Compute Engine bill per second with a 60-second minimum.
03What is a cold start?
When no instance is ready, the platform must first prepare one before the handler can run. That set-up time is the cold start.
04Three requests reach an AWS Lambda function at the same moment and one instance is already running. What happens by default?
On AWS Lambda each instance handles one request at a time by default, so the platform scales out automatically and runs the requests side by side. Some other platforms, such as Google Cloud Run, let one instance serve several requests at once.
05Which job suits a VM better than a serverless function?
Long, steady work fits a VM. AWS Lambda stops a single call after at most 15 minutes, and serverless shines for short, bursty tasks.
Glossary
- Compute
- Processing power, a CPU and memory, that runs your code. Cloud providers rent it out by the second or by the call.
- Physical server
- A real computer in a data centre. In the cloud, its CPU and memory are shared among customers.
- Hypervisor
- Software that splits one physical server into several isolated virtual machines and shares its CPU and memory among them.
- Virtual machine (VM)
- A slice of a physical server that behaves like a whole computer, with its own operating system. You choose its size and manage it.
- vCPU
- A virtual CPU: a share of a physical processor given to a VM. On many x86 cloud VMs it is one hardware thread of a physical core.
- Serverless function
- Your code, uploaded on its own. The platform runs it only when a request arrives and bills per request plus the time it runs.
- Cold start
- The extra wait before the first request when the platform has to start a new instance of your function.
- Scale to zero
- When no requests arrive, the platform removes every instance, so nothing runs and no run time is billed.
Notes and sources
- Counted seconds are not dollars: a second of function time usually costs more than a second of a small VM, so steady, busy traffic can be cheaper on VMs. The meters show time counted, not the bill: the VM is billed for every second it is on, while the function meter shows run time only and leaves out the billed cold-start time.
- Amazon EC2 (Linux) and Google Compute Engine bill VMs per second with a 60-second minimum. AWS Lambda bills a fee per request plus duration rounded up to 1 ms, scaled by the memory you choose (128 MB to 10,240 MB); since 1 August 2025 the cold-start (INIT) time is billed too.
- The 0.12 s run time is an assumed example, not a measurement. Real run times depend on the code and the memory setting.
- AWS Lambda calls an instance an execution environment. It keeps idle ones for a while before shutting them down, so a request soon after another one often skips the cold start.
- A vCPU is a virtual CPU, a share of a physical processor. On many x86 cloud VMs one vCPU is one hardware thread of a physical core.
- The code card is real Python 3. Called as handler({"name": "Ada"}, None) it returns "Hello, Ada". On Lambda you would name it in the function settings (often lambda_handler).
- NIST SP 800-125: Guide to Security for Full Virtualization Technologies
- NIST SP 800-145: The NIST Definition of Cloud Computing
- Amazon EC2 On-Demand Pricing (per-second billing, 60-second minimum)
- Google Cloud: VM instance pricing (billing model)
- Google Cloud: CPU platforms (what a vCPU is)
- AWS Lambda: Define Lambda function handler in Python
- AWS Lambda: Understanding the execution environment lifecycle (cold starts)
- AWS Lambda: Understanding function scaling (concurrency)
- AWS Lambda: Quotas (memory, 15-minute timeout)
- AWS Lambda Pricing
- Google Cloud Run: Concurrency (many requests per instance)
- AWS Compute Blog: AWS Lambda standardizes billing for INIT phase
Quiz Unlocks after the last step.