Key takeaways
- ✓A cold start is a request that finds no idle instance, so the platform creates one while the request waits: it fetches the code, starts the runtime, and runs the code outside the handler. A tiny Python function started its runtime in 68 ms (median), and a warm call of the same function ran its handler in 1.6 ms.
- ✓The imports were the cost: with numpy, pandas and Pillow imported at the top of a handler that never used them, Lambda's Init Duration went from 68 ms to 2,361 ms, the first call from the laptop took 2,984 ms, and 2,364 ms was billed.
- ✓Eight times the memory did not help: the same start-up took 2,394 ms at 1,024 MB against 2,361 ms at 128 MB, and the extra memory cost $31.93 more per million cold starts, against $3.94 at 128 MB.
- ✓The package costs time that Init Duration does not show: the same 33 MB package with nothing imported reported an 82 ms init, but the laptop waited 734 ms, about 400 ms more than for the tiny package.
- ✓Bursts make cold starts, not traffic: 240 requests a minute in steady spacing needed 3 instances and had 3 cold requests (1.25%), while the same 240 in bursts of eight needed 8 instances and had 8 cold requests (3.3%).
- ✓A request on Lambda cost $1.24 per million, of which $1.00 was API Gateway, the HTTP front door; two containers and a load balancer cost $51.10 a month from zero traffic, so the lines crossed at 15.7 steady requests a second, or 82 without the front door.
A Lambda function whose handler takes 1.6 ms to run took about 3 seconds on its first call. This chapter follows that first call apart: what a cold start is, where its time goes, what it costs, and how often real traffic hits one. Then it asks the second question: at what steady traffic does an always-on server cost less than paying per request?
The examples come from Lab 16 (Serverless and Event-Driven Compute) of the system design labs. The cold-start numbers come from 01_cold_starts.py, which deployed its test functions to real AWS Lambda in Amazon's us-east-1 region, on arm64 processors, using Python 3.13 and Node.js 22, and called them from an Apple M4 Max laptop over the internet. The costs come from 06_cost.py, which applies the public prices the lab fetched from the AWS Pricing API. Each configuration is one recorded run. The whole lab took about 45 minutes and cost a few cents on an AWS account.
What a cold start is
A function is code the platform runs once per request, on an instance: one running copy of your code. An instance handles one request at a time, so ten simultaneous requests need ten instances. Idle instances are kept for a while and then reclaimed, and you pay only while an instance runs.
When a request arrives and no idle instance is waiting, the platform starts one, and the request waits. That wait is a cold start. A cold start has three parts: fetching and unpacking the code, starting the runtime (the Python or Node.js program that will run your code), and running the code outside the handler, such as imports and connections. Lambda reports only that last part as Init Duration, in the report it writes at the end of each call. The handler itself, the function that answers the request, is reported separately.
Think of taxis. A warm instance is a taxi already waiting at the stand. A cold start is a request for which no taxi is waiting, so one has to come from the depot first. A server is your own car, paid for every month whether you drive it or not.
What the first request pays
The lab's test used six functions. Two were tiny: hello-py in Python and hello-node in Node.js, each about 0.3 KB of code, with nothing imported. heavy-py was a 33 MB package with three large libraries, numpy, pandas and Pillow, imported at the top of the file, although the handler never used them. lazy-py was the same package, with the imports moved inside the code that needs them. For each variant, the test forced 20 cold starts, changing a setting so the next call had to start a new instance, and then made one warm call.
| Variant | Init Duration, median | Billed, cold call | Laptop, cold call | Laptop, warm call |
|---|---|---|---|---|
hello-py, Python, 128 MB |
68 ms | 71 ms | 335 ms | 137 ms |
hello-node, Node.js, 128 MB |
144 ms | 158.5 ms | 426 ms | 138 ms |
heavy-py, imports at the top, 128 MB |
2,361 ms | 2,364 ms | 2,984 ms | 136 ms |
lazy-py, nothing imported at the top |
82 ms | 84.5 ms | 734 ms | 138 ms |
Every cold call reported an Init Duration and no warm call did, across all 20 rounds. A warm call of hello-py was billed 2 ms, and its handler ran in 1.6 ms. The runtime alone takes tens of milliseconds. The laptop's warm call of 137 ms is mostly the network to Virginia and back, and the cold call of 335 ms adds about 200 ms to it, of which Lambda reports 68 ms as Init Duration. The rest is not in Lambda's report.
Where the three seconds go
The heavy-py function is the story. Its first call from the laptop took 2,984 ms at the median, and the billed time was 2,364 ms. Breaking the laptop's cold call into parts gives roughly 2.4 seconds of Init Duration, which is nearly all imports, about half a second that Lambda does not report, and the 136 ms round trip of a warm call.
The code is three import lines and a handler that returns an answer. Python runs the top of a file when an instance starts, so every cold start loaded about 120 MB of libraries to serve a handler that takes under 2 ms.
Init 2360.7 ms (reported) · not in Init Duration 487.3 ms (derived: cold − warm − init) · the trip (a warm call, 136 ms). The split is a model; the three numbers it uses are recorded.
Package: 33 MB zip, 120 MB unpacked, 128 MB. Extra bill per million cold starts: $3.94 (billed time times memory, list price). Every cold call reported an Init Duration and no warm call did; one run of 20 rounds per variant.
Two tests tried to make the start faster, and they show what does and does not matter. More memory first: on Lambda, memory also buys processor share, so the same function was run at 1,024 MB, eight times the memory. Its init was 2,394 ms, no faster. The test shows that memory did not help this start-up, but not why. The second test was the package. lazy-py shipped the same 33 MB and imported nothing at the top, so Lambda's Init Duration was 82 ms, almost as fast as the tiny function. The laptop still waited 734 ms. The gap is most likely Lambda fetching and unpacking the bigger package before the init starts, which Init Duration does not count. A big package can cost time even when it imports nothing.
The start-up is on the bill
Lambda bills memory times time, and since August 2025 it bills the init phase as well, as the lab's README notes. So a cold start costs money as well as time. The tiny function's cold call was billed 71 ms against 2 ms warm. The heavy function's cold call was billed 2,364 ms, which is $3.94 more per million cold starts at 128 MB. At 1,024 MB, the same 2,397 ms of billed time cost $31.93 more per million, because eight times the memory is billed at eight times the rate, for a start-up that was no faster.
How often real traffic hits a cold start
The second test sent 240 requests through an HTTP front door (API Gateway) to a function that works for 100 ms on each request, once in steady spacing and once in bursts. Both took a minute.
- Steady, one request every 250 ms (four a second): 3 instances, and 3 cold requests, 1.25% of the total. The median request took 245 ms and the cold ones about 860 ms, measured from the laptop.
- Bursts, eight requests at once every two seconds: the same average rate, but 8 instances and 8 cold requests, 3.3% of the total. The cold ones took about 869 ms at the median.
Both patterns had 240 requests and all 240 succeeded. The likely explanation, which the lab's run is consistent with, is that the first burst needed all eight instances at once and after that they stayed warm. Steady traffic reached 3 instances, most likely because the first requests overlapped while the first start was still running, and after that each next request found a warm instance. Bursts make cold starts, and the traffic volume alone does not. A cold start also lives in the tail: it did not move the median, but it set the p99, the time the slowest 1% of requests take.
When a server is cheaper
A request on Lambda is billed for its duration and memory, and for the HTTP front door in front of it. The lab measured a warm read of one item from DynamoDB, a database, at 256 MB: 10.7 ms billed on average over 300 calls. At list prices, a million of those cost $1.24. Of that, $1.00 was API Gateway, $0.20 was Lambda's fee per request, and only $0.04 was the 10.7 ms of compute. Making the handler faster barely moves the bill. The front door does.
The alternative is two containers (Fargate tasks, Amazon's always-on container service) of 0.5 vCPU and 1 GB each, behind an Application Load Balancer. Two, so that one can fail. cost.py prices them at $28.84 for the tasks and $22.27 for the load balancer, $51.10 a month from zero traffic up. Lambda starts at zero and adds $3.25 a month for every extra request a second, around the clock. So the lines cross where $51.10 ÷ $3.25 ≈ 15.7 requests a second. Without API Gateway, calling the function through its own web address, the crossing moves to 82.
The container capacity, 2,000 requests a second per task in one model and 200 in another, was assumed rather than measured, and it does not change the crossing at these rates, because both sizes still run the minimum of two tasks. It only changes how fast the container bill grows after the crossing.
Traffic is rarely steady. For bursts of 100 requests a second and nothing in between, one busy hour costs about 45 cents on Lambda, so Lambda stays cheaper below about 115 busy hours a month, around four hours a day.
Lambda rows at 10 req/s steady, all month. Containers are two 0.5 vCPU, 1 GB tasks plus an Application Load Balancer, at $51.10 a month with no traffic. The Lambda side uses the recorded 10.7 ms billed mean at 256 MB. The rows are the cost model of the lab applied to list prices, not a bill.
The workflow and the results
- Set up.
00_setup.pyfetched the prices and deployed the functions to us-east-1. The laptop then calls the real Lambda endpoints. - Part A, cold versus warm. For each of 20 rounds and each variant, change a setting so the next call starts a new instance, call once cold, then once warm. Lambda's own report gives Init Duration and billed time; the laptop's stopwatch gives the client view.
- Part B, traffic. Send 240 requests in steady or bursty patterns through API Gateway, and count the instances that served them, and how many were first requests on their instance.
- Cost. Measure a warm read, then price the monthly bill at a range of steady request rates for Lambda and for the containers, and find the crossover.
The cost arithmetic uses the lab's price file, fetched from the AWS Pricing API on 4 November 2026.
Caveats
- One account, one region, one architecture. The numbers are for us-east-1, arm64 (Graviton) processors, and a laptop about 130 ms away. A function in a closer region, or on x86, would show different numbers.
- Init Duration is not the whole cold start. The "not reported" part, about 0.5 s for the heavy function and about 0.5 s for the lazy one, is the gap between the laptop and Lambda's report. The lab does not separate download, unpacking and network time.
- Small samples. Part A has 20 cold calls per variant. Part B has one run per pattern, one function and one request rate, four a second for steady traffic.
- Not tested: idle time. The lab did not measure how long an instance stays warm before Lambda reclaims it. The "cron once a minute" case is therefore a reasoned guess, not a result.
- Not tested: the fixes. Provisioned concurrency (instances kept warm, billed by the hour), SnapStart (restoring a saved start-up), and container images were not run. The lab lists them as exercises.
- The cost model is a model. It uses list prices, keeps the containers running all month, and leaves out the free tier, data transfer, and the database, which costs about the same either way. Without the load balancer's minimum capacity charge, about $5.84 a month, the crossover would be near 14 requests a second, by our arithmetic on the same model.
- Concurrency and connections were not part of this run. The lab's account allowed only 10 instances at once, so the lab's connection-spike exercise ran on a local platform, not on Lambda, and is not part of these numbers.
- Real deployments differ. Production functions often attach to a private network, call databases, and load bigger libraries than these tests. Each of those can change the start-up, and each is worth measuring on your own function before you decide.
The checklist
- Measure the cold start on your function. Read Init Duration from the report, then time the first call from the caller's side. The gap is the part the report does not show.
- Import at the top only what every request needs. Move the rest to where it is used, and measure the start-up again.
- Do not assume memory fixes a slow start. Test it, because you pay for the memory on every cold start.
- Expect bursts to cost cold starts. Traffic that arrives in spikes needs new instances at each spike, and the start-up is billed.
- Count the front door and the steady rate. For steady traffic above the crossover, containers are cheaper; for traffic that comes and goes, functions usually are.
Quiz
1.A function's handler runs in 1.6 ms, but its first call took about 3 seconds. Which part of that wait does Lambda report as Init Duration and bill?
2.Doubling a function's memory eight times made its import-heavy start-up no faster, and each cold start cost more. What is the right conclusion?
3.Using the lab's cost model, at what steady request rate does two 0.5 vCPU containers behind a load balancer ($51.10 a month) become cheaper than Lambda with API Gateway?
Check your understanding
Try each question before opening its answer.
A handler runs in 1.6 ms, yet the first call took about 3 seconds from the laptop. Where did the other seconds go?
Most of them were Lambda's Init Duration for the heavy function, about 2.4 seconds: starting the runtime and running the top-level imports of numpy, pandas and Pillow. About half a second was not reported by Lambda at all, most likely fetching and unpacking the package, and the rest was the round trip from the laptop, about 136 ms for a warm call.
Why did giving the heavy function eight times the memory make its cold starts more expensive without making them faster?
Memory buys processor share, but the start-up here was not held back by it: the init took 2,394 ms at 1,024 MB against 2,361 ms at 128 MB. Lambda bills memory times time, so eight times the memory was billed at eight times the rate, $31.93 more per million cold starts against $3.94 at 128 MB.
Steady traffic at four requests a second needed 3 instances, but bursts of eight needed 8. Why does the same average rate cause more cold starts when it comes in bursts?
A steady stream lets an instance finish one request and be ready for the next, so a few instances cover it, and only 3 of 240 requests were cold. A burst of eight at once needs eight instances at the same moment, and none are idle, so all eight start cold. After that they stay warm. The cold starts come from the spike, not the volume.
Why does making the handler faster barely change the monthly cost of a Lambda API?
Because the bill per request is mostly the front door and the request fee, not the compute. For the lab's read of one item, $1.00 of $1.24 per million requests was API Gateway, $0.20 was Lambda's per-request fee, and only $0.04 was the 10.7 ms of compute. Shaving milliseconds off the handler moves the $0.04.
Next up: Chapter 38, idempotent pipelines and dead-letter queues. An image pipeline of functions where the same upload arrives three times and one image is poison.