# Cold Starts and Autoscaling

> Why a model takes time to wake up, how autoscaling adds copies, and the trade-off between idle cost and waiting, explained for your AI interview.

**In short:** A cold start is the wait while a new copy of a model loads before it can answer. Autoscaling adds or removes copies as traffic changes. Scaling to zero saves money, but the first requests then wait, so a team picks a minimum that fits its traffic and its wait limit.

AI and LLM interview question Q332, Inference, performance and cost. Intermediate, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/cold-starts-and-autoscaling

## Say it in 30 seconds

A cold start is the wait for a new copy of a model to load before it can answer. Autoscaling adds copies when traffic rises and removes them when it falls. For a large model the load takes longer, and the wait grows with the model's size, so scaling to zero saves money but makes the first users wait. I would keep a minimum of warm copies for the morning peak, cap the maximum to control cost, and scale on GPU use or, as a beta option, on pending requests.

## Say it in 2 minutes

A model runs on replicas, which are copies of the model, each running on GPU hardware. Autoscaling changes how many replicas run as traffic changes. The catch is the cold start: a new replica has to download the model weights, load them into GPU memory and get ready before it can answer. For a large model that takes longer, and the wait grows with the model's size. Each new copy must finish that load before it can take a single request.

Scaling to zero saves the most on idle hours. When nothing has arrived for a while, the platform removes every replica, so the quiet hours cost little. The price is paid by the first users of the morning, who wait for a replica to load, or get an error if the platform does not queue requests. Keeping one warm replica removes that wait, but a GPU that stays on all night still bills all night.

Autoscaling also lags. On Hugging Face, scale-up runs every minute, so a sudden spike can queue up before the new replica is ready. So I would keep a minimum warm before the spike, scale on GPU use or, as a beta option, on pending requests, cap the maximum so a bad day cannot run up the bill, and test the cold path with a real burst from zero.

## What is a cold start, in plain words?

A model app runs copies of the model, called replicas. Each replica runs the model on GPU hardware, the fast chip that does the heavy maths. When traffic rises, the platform starts more replicas. When it falls, it stops some. That is autoscaling. Google's Cloud Run docs use the word instance for the same thing, so the two words mean the same here.

A cold start is the wait before a new replica can answer. Amazon's serverless service Lambda uses the same term: "When Lambda has to initialize a new environment to carry out an invocation, this is known as a cold start". A model replica pays the same kind of wait, and a longer one, because it has to load large weights first.

Think of a bank that opens an extra counter when the queue grows. The new clerk must sit down, log in and load the customer files before serving anyone. The first customers at that counter wait. A model replica does the same: it loads the weights before its first answer.

- **Replica:** One running copy of the model, on GPU hardware.
- **Weights:** The learned numbers that make up a model. They are the big files a replica must load.
- **Cold start:** The wait while a new replica loads before it can answer.
- **Scale to zero:** Stopping every replica when idle, to cut the bill.
- **Minimum replicas:** How many always stay running, so the first request is not cold.

## Why does loading a model take so long?

A new replica does three things before it can answer: it fetches the model files, loads the weights into GPU memory, and gets the runtime ready. Hugging Face, which hosts model endpoints, describes the first two: "During the initialization of a new replica, the model is downloaded and loaded into memory."

The wait also grows with the model. Hugging Face says that "The duration of the cold start period varies depending on your model's size." A bigger model means a longer wait before the first answer, so you can measure the cold start as a real cost.

*Diagram, What a cold start adds: A new request finds no replica. The platform fetches the model, loads it into GPU memory, and only then answers. The wait sits in the middle, so the first user pays for it. Later requests skip that step while the replica stays up.*
1. The first request finds no replica running.
2. The platform downloads the model files.
3. The weights are loaded into GPU memory before any answer.
4. The ready replica answers, after the whole wait.

> **Tip:** Cloud Run's GPU guide advises models that load fast. It also says: 'Your container can use the GPU as soon as the startup finishes.' Choosing the model format and where the files load from changes the cold start too.

## What does a waiting user actually get?

It depends on the platform, and a good answer says so. Google's Cloud Run balances two waits. Its guide says that "Since on-demand scaling responds in real time to sudden traffic changes, Cloud Run manages the trade-off between cold start latency (the time to start a new instance) and pending queue latency (the time a request waits for a slot to open on an existing instance)". So some platforms hold the request and others fail it.

> "Since on-demand scaling responds in real time to sudden traffic changes, Cloud Run manages the trade-off between cold start latency (the time to start a new instance) and pending queue latency (the time a request waits for a slot to open on an existing instance)" (Google Cloud Run)
>
> "after scaling in to zero instances, your endpoint can't respond to any incoming inference requests until it provisions at least one instance" (Amazon SageMaker)
>
> "there is currently no queueing system in place for incoming requests" (Hugging Face)

Hugging Face's endpoints go a step further: the HTTP server "will respond with a status code 502 Bad Gateway while the new replica is initializing". With no queue on its side, the app needs its own retry queue and clear error messages for the user.

## Should you scale to zero or keep one warm?

- **Scale to zero: Cheapest at night.** Nothing runs when idle, so the platform can stop billing it. Azure says you are not billed usage charges when an app scales to zero. The first requests of the morning pay the cold start.
- **Keep one warm: Fastest first answer.** The first request is never cold. The cost is a replica that stays loaded and bills while it sits idle.

*Diagram, Scale to zero or keep one warm: Scale to zero saves the idle hours but makes the first requests wait. Keeping one warm answers at once but bills while it sits idle. Pick by who waits.*
1. With no replica at night, the morning's first requests start a cold start.
2. A warm replica answers at once, and its idle hours still cost money.

Cloud Run's GPU guide says that "minimum instances are charged at the full rate even when idle". Lambda's warm option also costs extra: "Configuring provisioned concurrency incurs additional charges to your AWS account". Warm capacity is a standing cost, so it should match a real need.

Some jobs do not need it. Lambda's guide says that "Asynchronous workloads, such as data processing pipelines, are often less latency sensitive and so do not usually need provisioned concurrency". A nightly batch can take a cold start, but a live claims screen cannot.

A made-up insurance firm runs a claims triage model. Claims start arriving at 09:00, and a replica takes a made-up 180 seconds to load. The script below counts how many of 14 early requests wait, under two settings.

```python
# A made-up claims-triage model at 09:00. A replica takes 180 seconds to load (made-up).
# Simplified: one replica serves every request once it is ready, so only the cold wait is counted.
LOAD = 180
ARRIVALS = [0, 2, 5, 9, 14, 20, 30, 45, 60, 90, 120, 150, 200, 260]  # seconds after 09:00

def waits(min_replicas):
    ready = [0] * min_replicas  # the second each replica can serve
    result = []
    for t in ARRIVALS:
        if not ready:
            ready.append(t + LOAD)  # no replica at all: start loading now
        result.append(max(0, min(ready) - t))
    return result

for n in (0, 1):
    w = waits(n)
    print(f"min replicas {n}: {sum(x > 0 for x in w)} of {len(w)} requests waited, longest {max(w)} s")
```

Output:

```text
min replicas 0: 12 of 14 requests waited, longest 180 s
min replicas 1: 0 of 14 requests waited, longest 0 s
```

With scale to zero, 12 of the 14 requests wait, the longest three minutes. With one replica kept warm, none of these early requests wait for a cold start. A burst of many claims at once would still queue behind that one replica. The warm replica also runs through the night, which is the cost side of the same trade-off. The simplified script counts only the cold wait, so the real numbers depend on the platform and the traffic.

> **Tip:** Ask one question first: does a person wait for this answer? If yes, plan warm capacity for those hours. If no, scale to zero and let the batch wait.

## What should the autoscaler watch, and how fast does it react?

An autoscaler watches a signal and adds replicas when it crosses a target. On Hugging Face, the GPU rule is: "A new replica is added when the average GPU utilization of all replicas over a 1-minute window reaches 80%". The platform also offers a beta option based on pending requests, which include requests in progress. By default, a replica is added when there are more than 1.5 pending requests per replica in the past 20 seconds.

Reaction is slow for two reasons. Hugging Face says that "the scaling up process takes place every minute and scaling down takes place every 2 minutes", so a spike can build before anything new starts. The new replica then needs its own cold start before it helps. Scale-down is slower still: after each scale-down, a stabilisation period of 300 seconds keeps the count steady.

*Diagram, Why autoscaling arrives late: A burst of claims arrives in one minute and queues while the replicas are full. The scaler adds a replica on its next check, and that replica helps only after its own cold start. The relief comes late, so warm capacity has to be planned ahead of the spike.*
1. A burst of claims lands in one minute and piles up.
2. The scaler sees the queue on its next check.
3. The new replica helps only after its own cold start.

Cloud Run's guide lists the same settings: custom targets, and "setting minimum and maximum instance limits". The minimum keeps capacity ready. The maximum is a cost cap, so a bad day cannot run up the bill.

1. **Set minimum replicas for the known peaks:** Keep one or more warm through claim hours, so the morning spike lands on a ready replica.
2. **Scale on the right signal:** GPU use is the standard rule on Hugging Face. Pending requests is a beta option, so test it before you rely on it.
3. **Cap the maximum:** The maximum is a cost cap, sized to the peak you have measured.
4. **Hold a queue if the platform has none:** Hugging Face has no queue, so the app keeps its own retry queue and shows a clear message.
5. **Test the cold path:** Run a burst from zero, time the first answer, and check the bill for the warm hours.

### How would you stop 9 am claims from waiting?

A claims team says the first ten minutes after 9 am are slow, but keeping a GPU warm all day is too expensive. Here is how I would approach it.

1. **Measure first:** Pull the start times, the queue length and the first-answer time for the last month.
2. **Keep one replica warm during claim hours:** Set the minimum to one from before 9 am until the queue is empty, then let it scale to zero overnight.
3. **Warm up before the bell:** A warm-up request sent a few minutes before 09:00 starts a replica before the first claim arrives.
4. **Keep a ceiling:** Set the maximum from the measured peak, so a surge cannot run up the bill.
5. **Show the trade-off:** Put the cost of the warm hours next to the waits saved, and let the business choose the balance.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the wait while a new replica loads.
- [ ] Why it is slow: model files and weights load into GPU memory.
- [ ] Scale to zero versus keep warm, with the cost of each.
- [ ] What a waiting user gets: a queue or an error, depending on the platform.
- [ ] Why autoscaling lags, and which signal you pick.
- [ ] How you would test it with a real burst from zero.

**Common traps**

- Trap: "Autoscaling fixes slow starts." Better: It adds copies, but each new copy still pays the cold start, so the spike can arrive first.
- Trap: "Scale to zero is always the cheapest." Better: It saves idle hours. Count what the first waits cost the users too.
- Trap: "Just add more GPUs." Better: More replicas cost more, and each one still starts cold. Warm the first one, then scale on the queue.

## Can you spot the cold start?

**Spot the cause:** The claims team says the first minutes after 9 am are slow every day. Which setting is the cause?

A. min_replicas: 1 during claim hours, max_replicas: 6
B. min_replicas: 0 overnight, max_replicas: 6, no warm-up before 9 am
C. min_replicas: 1 all day, max_replicas: 6
D. scale on pending requests, 1.5 per replica over 20 seconds

**Answer:** B. Scaling to zero overnight means the first claims of the day start a cold start, and nothing warms a replica before 9 am. The other settings keep a replica warm all day or set a cap and a signal, so none of them is the cause.

**Quick check:** A model replica can take a long time to load, and the wait grows with model size. Which change most cuts the wait at the 9 am spike?

A. Raise the maximum replicas to 20
B. Keep one replica warm before 9 am, or scale up ahead of it
C. Use a longer system prompt
D. Lower the temperature setting

**Answer:** B. A replica that is still loading cannot answer, so more maximum replicas and a longer prompt do not help the first minutes. A warm or early replica is ready when the spike lands. Temperature only changes how varied the answers are.

## Can you answer these from memory?

**Flash cards**

- **What is a cold start?** The wait while a new replica loads the model before it can answer.
- **Why is it slow?** Model files download and the weights load into GPU memory first.
- **What is scale to zero?** Stopping every replica when idle, to cut the bill.
- **What does a warm replica cost?** On Cloud Run, minimum instances bill at the full rate even when idle.
- **Why does autoscaling lag?** Hugging Face scales up every minute, and the new replica still needs its cold start.
- **What does a 502 mean here?** Returned while a replica starts after scaling to zero. Hugging Face has no queue, so the app must retry.

## Likely follow-up questions

- Q330 How do you handle rate limits and 429 errors? https://designervenkat.online/interview/ai/how-do-you-handle-rate-limits-and-429-errors
- Q331 When do you use batch APIs? https://designervenkat.online/interview/ai/when-do-you-use-batch-apis
- Q333 On-device inference? https://designervenkat.online/interview/ai/on-device-inference
- Q334 How do you cut cost on a cloud-hosted LLM workload? https://designervenkat.online/interview/ai/how-do-you-cut-cost-on-a-cloud-hosted-llm-workload
- Q337 Timeouts, retries and backoff? https://designervenkat.online/interview/ai/timeouts-retries-and-backoff
