Outcome
By the end of this lesson, you will be able to explain what serverless means, say how it is billed, and judge when it is cheaper or dearer than a machine left running.
| Prerequisites | L1, I.3 L1 |
| Time | 7 minutes |
1. Concept
“Serverless” does not mean there are no servers. There are. It means you do not rent or manage them. You hand the provider a small piece of code, called a function, and the provider runs it on its own machines whenever it is needed.
The best-known examples are AWS Lambda, Google Cloud Run functions and Azure Functions.
A useful picture: a VM is like hiring a taxi for the whole day, waiting outside in case you need it. Serverless is like calling a taxi only when you need a ride, and paying for that ride alone.
When the code runs
A function sits doing nothing until something triggers it. A trigger might be a visitor clicking a button, a file arriving in storage, or a timer that goes off every hour. The function starts, does its job, and stops. Most functions run for a fraction of a second up to a few minutes.
How serverless is billed
Two meters, both from I.3:
- Per request. A tiny charge every time the function is called. Usually published per million requests.
- Per GB-second. A charge for how long the function ran, multiplied by how much memory you gave it. One GB-second is one gigabyte of memory used for one second. A function with 0.5 GB of memory that runs for 2 seconds uses 1 GB-second.
When nothing calls the function, both meters read zero. That is the big attraction: no idle cost.
All three providers include a free monthly allowance of requests and GB-seconds. The amounts change, so check the pricing page.
When it is not cheaper
Serverless wins for work that is light or comes in bursts with long quiet gaps. It can lose for work that is busy all the time. If a function is being called constantly, all day and all night, the per-request and per-GB-second charges can add up to more than a machine that simply stays on.
Watch for the other things a function touches, too. The storage it reads, the database it writes to and the data it sends out are all billed separately, in the usual way.
2. Worked example
A small function resizes photos that customers upload. It has 0.5 GB of memory and runs for 1 second per photo. Prices are illustrative, and the free allowance is ignored to keep the sum simple.
| Meter | Amount | Unit price | Monthly cost |
|---|---|---|---|
| Requests | 1 million | $0.20 per million | $0.20 |
| Compute | 1 million x 0.5 GB x 1 second = 500,000 GB-seconds | $0.00002 per GB-second | $10.00 |
| Total | $10.20 |
A small VM left on all month to do the same job, at an illustrative $0.05 per hour, would cost 730 x $0.05 = $36.50, and most of that time it would be waiting.
Now imagine traffic grows a hundred times, to 100 million photos a month. The function would cost about $1,020. At that volume, a few machines left running could be cheaper. The shape of the work decides which wins.
3. Hands-on (5 min: no account needed)
1. Open the AWS Lambda pricing page: aws.amazon.com/lambda/pricing2. Find the price per 1 million requests.3. Find the price per GB-second for the first pricing band.4. Find the free allowance included each month.5. Work out the cost of 3 million requests at 0.25 GB of memory and 0.5 seconds each, before the free allowance.Then subtract the free allowance and see how much is left. For light workloads, it is often close to nothing.
4. Knowledge check
Q1
What does “serverless” mean?
A. The code runs with no computers involved at any point
B. The code runs only on your own laptop
C. Servers are rented by the year at a discount
D. The provider runs your code on its machines when needed
Show answer
Correct: D. There are still servers, but you do not rent or manage them. The provider runs the function when it is triggered.
Q2
A serverless function is not called at all for a whole week. What does it cost for that week?
A. The full hourly price of a small machine
B. Close to nothing, because both meters read zero
C. A fixed weekly fee for keeping the function ready
D. Double, because the function had to be kept warm
Show answer
Correct: B. Serverless is billed per request and per GB-second. No calls means no requests and no running time. Storage or other services the function uses may still bill separately.
Q3
When can serverless cost more than a machine left running?
A. When the function is called constantly, day and night
B. When the function is called only a few times a day
C. When the function has a free monthly allowance
D. When the function is never called at all
Show answer
Correct: A. Constant, heavy use adds up request and GB-second charges until a machine that stays on becomes cheaper. Light or bursty use is where serverless wins.
5. Apply
When you see a serverless line on a bill, read it as two numbers: how many times the code ran, and how long it ran for. If the line is growing fast, ask whether the work has become steady and heavy. That is the point at which it is worth comparing with a machine that stays on.