# Serverless and FaaS

> How serverless code runs only when something happens, and costs nothing when nothing does. Where it shines, and the cold start that comes with it.

**Course:** [Virtualization and Cloud Computing](https://learn.benibix.com/learn/infrastructure-virtualization)  
**Time:** 11 min

**After this lesson you can:**

- Explain what serverless means
- Write the shape of a cloud function
- Say when serverless is a poor fit

## Code that runs only when something happens

Serverless computing means running code with no server to look after, and paying only while it runs. There are still servers, but the cloud runs them and you never see them. You upload a small function, and the cloud starts a copy each time an event calls for it. With no events, it costs nothing.

An event is anything that should start the code. A photo is uploaded. A web request arrives. A timer goes off every hour. Each one starts a copy of your function, which does its job and stops.

Function as a Service, or FaaS, is the most common kind. You write one function, set what starts it, and upload it. If 300 events arrive at once, the cloud runs 300 copies. At night, it runs none.

The bill is counted in tiny pieces, often by the millisecond, plus a small charge per call. A job that runs a few thousand times a day can cost a few cents a month.

There are limits. A function must finish within a set time, often up to 15 minutes. It keeps nothing in memory between calls. So anything it needs to keep goes in a database or in storage.

The first call after a quiet spell is slower. The cloud has to start a fresh copy, which can add from a tenth of a second to a few seconds. This is called a cold start, and it matters most for pages a person is waiting on.

The mistake is to use it for a job that runs all day. A function busy every second of the day can cost several times more than a small server doing the same work. Serverless is cheapest when the work comes in bursts.

```javascript
export const handler = async (event) => {
  return { statusCode: 200, body: 'Hello' };
};
```
A whole cloud function. The cloud calls it once per event and passes the event in.

![Three events on the left, a photo uploaded, a web request and an hourly timer, each start a copy of your function in the middle. On the right, a bar chart of copies running through one day: a few in the morning, a tall spike of 300 at once in the lunch rush, then nothing at night, marked zero copies and zero cost.](https://learn.benibix.com/diagrams/inf6-serverless.svg)

### Example: A photo shrinker that costs pennies

A recipe site lets users upload photos. Each one must be shrunk to three sizes. Uploads come in bursts after dinner and almost none at night.

A function runs on each upload and takes about half a second. With 2,000 uploads a day, the monthly bill is under a dollar, and no one patches a server.

**Words in this lesson:** [Serverless Computing](https://learn.benibix.com/term/infrastructure/serverless-computing), [Function as a Service (FaaS)](https://learn.benibix.com/term/infrastructure/function-as-a-service)

**Question:** When does serverless cost more than a small server?

**Answer:** When the function is busy all day, every second. You pay for every millisecond a function runs. Work that never stops is cheaper on a server you rent by the month, which costs the same busy or not.

---

Source: https://learn.benibix.com/learn/infrastructure-virtualization/serverless-and-faas
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
