TL;DR
|
A cold start is the extra time it takes to handle a request or job when nothing is running yet to handle it. The system has to create a new instance of your code, load it, and get it ready before it can do the actual work.
You notice cold starts as a slow first request after a quiet period, or a delay before a background job begins. This guide explains where cold starts happen, what causes them, and how to reduce them.
Key takeaway: a cold start creates something new, a warm start reuses something already running.
| Cold start | Warm start | |
|---|---|---|
| What happens | A new instance is created and initialized | An instance that's already running handles the work |
| Speed | Slower, from a fraction of a second to many seconds | Fast |
| When it happens | The first request after idle time, a sudden traffic spike, or a new on-demand job | Ongoing traffic to running instances |
Key takeaway: anything that starts on demand or scales from zero can have cold starts.
| Where | Why it happens |
|---|---|
| Serverless functions | Platforms stop idle functions and start them again when a request arrives |
| Containers that scale to zero | Services that shut down when idle must start a container for the next request |
| Autoscaling | New instances added during a spike need time before they're ready |
| On-demand jobs | Batch jobs or tasks that start a fresh container for each run |
| AI agents | Agents that start a new, isolated environment for each task, and AI apps that load large models into memory |
Key takeaway: a cold start adds up several steps, and the slowest is often your own app's startup work.
| Step | What happens | What makes it slow |
|---|---|---|
| Find capacity | The platform finds somewhere to run the new instance | Busy platforms, or large resource requests |
| Load the image or code | The container image or code package is fetched | Large images with unneeded files |
| Start the runtime | The language runtime starts, such as Node.js, Python, or Java | Some runtimes take longer to start than others |
| Initialize the app | Your code loads libraries, reads configuration, and connects to databases | Heavy frameworks, many dependencies, slow connections |
| Warm caches | The app fills caches or loads models into memory | Large caches or AI models |
Key takeaway: make startup lighter, or keep something running so cold starts happen less often.
| Approach | How it helps |
|---|---|
| Keep a minimum running | Keep at least one instance always running for latency-sensitive services |
| Use smaller images | Remove build tools and unneeded files, so there's less to load |
| Start faster | Load only what's needed at startup, and do heavy setup later or in the background |
| Reuse connections | Open database connections once per instance, not per request |
| Warm up before traffic | Check an instance is ready before sending it requests |
| Choose the right model | Use always-running services for frequent, short work, and on-demand containers for occasional, longer jobs |
Key takeaway: isolating every agent task in a fresh environment adds a startup cost, which is usually worth it for safety.
Running each AI agent task in its own fresh, isolated environment is good for security, because nothing carries over between tasks. It also means each task pays a startup cost. For tasks that run for minutes, a short start is a small price for the isolation. For many tiny, frequent tasks, a long-running worker may suit better.
Our guide What is an AI agent sandbox? explains why isolation matters.
Key takeaway: on Upsun Cloud, apps and workers are always running, and task containers start on demand, so choose based on how often work arrives.
The Upsun docs on tasks compare the ways to run code:
| Apps | Workers | Task containers | |
|---|---|---|---|
| Lifecycle | Always running | Always running | Start on demand, run to completion, then removed |
| Cold starts | Web requests reach running instances | Jobs are picked up by running workers | Each run starts a new container |
| Good for | Web traffic | Frequent background jobs | Occasional heavy jobs, data exports, background AI agents |
A few details from the docs:
post_start command can check the app is ready before the router sends it traffic, so the first visitors don't hit an instance that's still starting up.For work that arrives constantly, use a worker. For occasional, heavier jobs that benefit from a fresh, isolated container, use a task container. Our guide Background jobs vs cron jobs: which do you need? compares the options.
You can deploy on Upsun Cloud free for 15 days, with no card needed, or see how task containers work on Upsun Cloud.
What is a cold start in serverless?
The delay when a serverless platform starts a new instance of a function to handle a request, because no instance is already running.
What is the difference between a cold start and a warm start?
A cold start creates and initializes a new instance. A warm start uses an instance that's already running, so it's faster.
How long does a cold start take?
It varies widely, from a fraction of a second to many seconds, depending on the platform, the image size, the runtime, and the app's startup work.
How do I avoid cold starts?
Keep a minimum number of instances running, make your app start faster, use smaller images, and use always-running services for latency-sensitive work.
Do containers have cold starts?
Yes, when a new container has to be started to handle work, such as when scaling from zero or adding instances during a spike.
Why do AI agents have cold starts?
Agents often start a fresh, isolated environment for each task, and AI apps may need to load large models into memory before they can respond.