Sub topic 16
Scale to Zero and Its Trade-offs
Assume you understand model-serving endpoints, Kubernetes Deployments, latency percentiles, and basic autoscaling. This chapter focuses on one decision: whether a model service should run no replicas when it has no traffic.
Scale to zero means an autoscaler reduces a service to zero running model replicas during an idle period. When a new request arrives, the platform creates a replica, loads the model, warms up the runtime, and then sends the request to it. This saves compute cost during idle periods, but the first request pays the startup cost.
The request path after an idle period
A warm replica can often begin inference immediately. A scale-to-zero service must complete several steps first:
- The autoscaler detects demand.
- A container is scheduled.
- The image is downloaded if it is not cached.
- The model server starts.
- Model weights are loaded into memory or accelerator memory.
- Kernels, memory pools, and connections warm up.
- The request reaches the replica and runs inference.
The total cold-start delay can range from seconds to minutes. Large model weights, scarce accelerators, image pulls, and slow storage increase this delay.
When scale to zero is appropriate
Scale to zero fits workloads with predictable idle periods and a tolerant first-request experience. Examples include development endpoints, internal tools, scheduled jobs, and low-volume batch APIs.
It is usually a poor fit for interactive user-facing APIs with strict p99 latency objectives. A single request after an idle period can violate the objective even when all warm-request measurements look healthy.
Consider more than average traffic. A service receiving one request every few minutes may spend most of its time idle, so scale to zero can reduce cost substantially. A service receiving requests continuously gains little from scale to zero because it quickly returns to at least one replica.
| Condition | Scale-to-zero implication |
|---|---|
| Long idle periods | Cost savings can justify cold starts |
| Strict first-request latency | Keep at least one warm replica |
| Large model or slow accelerator allocation | Cold-start risk is high |
| Predictable traffic windows | Scheduled warmup may work well |
Estimating the trade-off
Separate warm-request latency from cold-start latency. If cold starts happen rarely, p50 may hide the problem while p99 exposes it. Track the percentage of requests that arrive during a zero-replica period and measure their complete latency.
The following small model compares monthly idle cost with the latency penalty of cold starts. It does not choose a policy automatically, but it makes the assumptions visible.
def monthly_idle_cost(replicas, hourly_cost, idle_hours):
return replicas * hourly_cost * idle_hours
def cold_start_request_seconds(requests_after_idle, cold_start_s):
return requests_after_idle * cold_start_s
idle_cost = monthly_idle_cost(
replicas=1,
hourly_cost=2.40,
idle_hours=300,
)
penalty_seconds = cold_start_request_seconds(
requests_after_idle=40,
cold_start_s=45,
)
print(f"warm replica idle cost: ${idle_cost:.2f}")
print(f"cold-start delay imposed: {penalty_seconds:.0f} request-seconds")The dollar calculation is only one side of the decision. Assign a business cost to timeouts, abandoned requests, or a poor first interaction. If that cost exceeds the saved compute cost, keep one replica warm or use a smaller warm gateway that activates the expensive model.
Practical policies
Use a minimum of one replica when the endpoint has a strict latency objective. Use scale to zero when occasional startup delay is acceptable and idle cost matters. A middle option keeps a lightweight router or small model warm while the larger model scales from zero.
If you use scale to zero, reduce cold-start time by caching container images, storing weights close to the compute environment, loading only required model components, and warming the model with a synthetic request. Set a request timeout longer than the expected startup path, or return an explicit retryable response rather than silently timing out.
Exercise
A service receives one request every 20 minutes, and each cold start takes 50 seconds. Its users require p99 latency below 2 seconds. Should it scale to zero without another mechanism?
Show answer
No. Each request is likely to encounter a cold start, so p99 will exceed the objective. Keep one warm replica, schedule warmup before expected traffic, or change the user-facing contract to allow delayed processing.