1,500 requests a day, 60,000 in an hour
Those are the two numbers of a city football league's renewal API: about 1,500 requests on an ordinary day, and 60,000 in the first hour after the renewal email reaches 40,000 players. Servers sized for that hour sit almost idle the rest of the year; a server sized for an ordinary day falls over on the one morning that matters.
Serverless functions fit that shape. You hand the platform your code, and it runs it each time an event arrives, on as many copies at once as the events need within the platform's limits, and, unless you keep some warm, on none when nothing arrives. You pay for the runs, not for machines waiting. There are still servers; the league no longer chooses, patches or counts them.
A function and the event that wakes it
A function is a handler: code that receives one event, does its work and returns. Its trigger decides what the event is: for the league, an HTTP request through an API gateway when a player renews, a queue message for each receipt to email, and a nightly schedule that reminds players who have not renewed (Scheduled jobs & cron). An event can be delivered more than once, after a retry or a timeout, so the receipt function has to recognise a receipt it already sent (Idempotency & exactly-once illusions). AWS Lambda, Azure Functions and Google Cloud Run functions run in a cloud region; Cloudflare Workers runs at the network edge. The code goes up as a zip archive or, on some platforms, as a container image (Containers & orchestration).
API Gateway only forwards. The renewal function writes the member's row and queues the receipt, and a second function, triggered by the queue, sends it.
Nothing survives between calls, except by luck
To run a function, the platform creates an instance, an isolated environment with the runtime and your code loaded, and sends it events. By default on Lambda an instance handles one event at a time, so 30 renewals arriving together run on 30 instances; Cloud Run and Workers let one instance serve many requests at once. After a call, the platform may keep the instance for the next event, send that event elsewhere, or discard it. You do not choose.
The league's first version kept a count of today's renewals in a variable. It worked in testing, on one warm instance; in production every instance had its own count, and each new one started from zero. Functions are stateless by design: anything that must outlive one call goes to a database, a cache or a queue. Memory is for what is fine to lose and rebuild, such as parsed configuration or a database client created once per instance and reused while it stays warm.
The first request pays for the start
A new instance is not ready at once. The platform finds capacity, loads the runtime and your code, and runs your initialisation, such as importing libraries and opening that database client, before it handles the event. That delay is a cold start: tens of milliseconds for a small function on a light runtime, seconds for a large package or a heavy runtime. On renewal morning:
- The email goes out, and renewals jump from about one a minute to 17 a second on average over the hour, more in its first minutes.
- While the spike climbs, a request that finds every warm instance busy can make the platform start another, within its limits, and that player waits through a cold start.
- Once enough instances are warm, most requests reuse one.
- Over the quiet hours that follow, the platform discards idle instances, down to none unless you keep capacity warm: scale to zero.
How many instances? On Lambda, where each serves one request at a time, roughly requests per second times seconds per request: 17 renewals a second at 400 ms each keep about 7 busy. A slow payment provider that stretches each call to 4 seconds makes it about 70, for the same players.
Keep the package small and the initialisation light. Where latency matters, ask the platform to keep some instances initialised: provisioned concurrency on Lambda, minimum instances on Cloud Run. Those are billed while they wait, so you have bought back a small fleet, sized by you. Pinging a function every few minutes keeps about one instance warm, and does nothing for the fortieth a spike needs. Cold starts also stack: if the renewal function synchronously calls a pricing function that calls a discount function, one request can wait through three, and where duration is billed each caller pays for its wait. Work the player need not wait for, like the receipt, goes on a queue (Message queues & async workers).
Ceilings you set and ceilings you hit
Most platforms cap concurrent instances; on AWS Lambda the default is 1,000 per account and Region, shared by all its functions and raisable on request. Past the cap, synchronous calls are rejected with a throttling error, while asynchronous events are held and retried for a while. You can also cap one function, which eases the pressure on a database that limits connections: had the league kept its members in PostgreSQL, which accepts 100 connections by default, a renewal function capped at 50 concurrent executions would turn players beyond the cap away with an error to retry instead of letting the database fall over. The cap limits executions, not open connections, since an idle warm instance can still hold one, so a connection pooler or proxy in front of the database is what caps the total.
Each invocation also has a time limit and a memory size. On Lambda the timeout goes up to 15 minutes and memory from 128 MB to 10,240 MB, with CPU allocated in proportion to memory. A job that outgrows the timeout, like the league's end-of-season export, gets split into pieces, one queue message each, and work that is long by nature, such as transcoding match videos, fits workers or containers better (Media processing & transcoding).
Paying for runs, until runs are all you do
On Lambda the bill has two meters: a fee per invocation, and duration multiplied by memory, in GB-seconds. A renewal that runs 400 ms with 512 MB uses 0.2 GB-seconds; 60,000 of them use 12,000, and the charge stops when the renewals do. Lambda bills wall-clock time, waits included, while Cloudflare Workers bills CPU time, so time spent waiting on the payment provider is billed on the first and not on the second.
That model wins when traffic is spiky or low, because idle time costs nothing unless you keep instances warm. It often loses on a steady, heavy load: a service handling 300 requests a second around the clock pays for every one, while a few always-on servers kept busy can carry the same load at a fixed price, often a lower one.
Closer to the player, with less room
Edge functions run the same model in many locations, often a CDN's points of presence, so a request is handled near the user instead of in one region. Many edge runtimes run code in lightweight isolates of a JavaScript engine rather than a full instance per function, and their cold starts are often a few milliseconds. The price is less room: CPU time per request counted in milliseconds on some plans, a restricted set of APIs instead of a full operating system, and smaller code bundles.
The edge suits work that needs only the request: a redirect, a signed-cookie check, a header, a choice between cached pages (CDN & static delivery). It is the wrong place for the renewal. The league's database lives in one region, and a function in Sydney that makes five queries in a row to a database in Frankfurt pays the intercontinental round trip five times, ending up slower than a function next to the database. How a platform keeps one customer's function apart from another's, with microVMs such as Firecracker on Lambda or V8 isolates on Workers, is Sandboxing untrusted code: isolation, limits & egress.
Draw renewal morning
Build the league in the Serverless Web App on AWS Challenge: the renewal function behind API Gateway, the receipt on SQS, the reminders on an EventBridge schedule. For each function, decide what it may keep in memory and what must go to DynamoDB, and which one would get slower at the edge. The Serverless Function Platform Challenge turns the view around: you design the platform underneath, with its pre-warmed pool, scale to zero and per-tenant concurrency limits.